First you are opening the file '$file' for writing and this should be deleting the contents of $file because you have used >. To open a file for reading you use <$file. You are not checking to see if the files are opened successfully. You need to binmode OUT. I think you also need parens for the read within the while loop because of precedence issues. Finally you are reading the data in 1 byte at a time which is a very small buffer! 4-8-16kB chunks is much more efficient as with a 16kB buffer the script makes 16384 times less calls to the while loop and read function! Here is some code that should work for you:

my $infile = "some file" my $outfile ="/the/path/to/the/file/$AdsID.jpg" open(IN, "<$infile") or die "Unable to open $infile for reading: Perl +says $!"; open(OUT,">$outfile") or die "Unable to open $outfile for writing: Per +l says $!"; binmode IN; binmode OUT; while (read(IN, $data, 16384)) { print OUT $data; } close OUT; close IN;

Hope this helps

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Upload an image file by tachyon
in thread Upload an image file by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.