PDA

View Full Version : Cannot read uploaded file


yaman666
08-16-2007, 02:49 AM
I am trying to trouble shoot a site that used to upload files ok but then stopped working. The person responsible for the site before is not available so I have no information as to what may have happened.

I created a new basic upload form using a tutorial. I used the proper form enctype='multipart/form-data'. Relevant code:

$query = new CGI;
$filename = $query->param("photo");
# print $filename prints the actual file name ok
$upload_filehandle = $query->upload("photo");
# print $upload_filehandle prints the actual file name ok
while ( <$upload_filehandle> ) {
# inside of while loop never reached
....
}

Basically file handle opens ok and prints out file name, but I can never read the actual file whether it's while (<$file_handle>) or read ($file_handle ...).

Any suggestions?

Thanks!

KevinADC
08-16-2007, 02:57 AM
where have you opened the file to upload the data into?

my $upload_dir = "/home/mywebsite/htdocs/upload";
my $upload_filehandle = $query->upload("photo");


open (UPLOADFILE, ">$upload_dir/some_file_name") or die "$!";
binmode UPLOADFILE;
while ( <$upload_filehandle> ) {
print UPLOADFILE;
}
close UPLOADFILE;

yaman666
08-16-2007, 02:59 AM
Saving file works just fine, creates 0kb empty file. (since while fails)

I actually figured out that the problem is the screwed up /var/tmp directory - can't save files there and it's set as temp directory in $CGITempFile::TMPDIRECTORY. Is there any way to change temp directory while that's being troubleshot?

This is a hosted solution, so I don't have access to most of the server. Don't have access to apache configuration for example.

KevinADC
08-16-2007, 04:45 AM
Try overloading the variable in your uploader script:

$CGITempFile::TMPDIRECTORY = 'path/to/other/dir';

but check to see it gets cleaned up afterwards.

yaman666
08-16-2007, 07:01 PM
That worked, thanks a lot!