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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |