in reply to Problem with file upload CGI script

Hi

1) you should do something like
my $query=new CGI(); my $filename=$query->upload("uploaded_file"); if( defined($filename) ) { # save the uploaded file open(OUTPUT, ">1.jpg"); # just an example, you should check the type binmode($filename); binmode(OUTPUT); while( read($filename, $buffer, 64*2**10) ) { # filename is a file ha +ndle here print OUTPUT $buffer; } close(OUTPUT); print $query->header(); print $filename; # it's a string here; original filename returned (th +e name on client's harddrive, fullpath/filename } else { # print the form print $query->header(); ... print $query->end_html(); }
This code was written by memory, not tested. I wrote a similar script just a few days ago. Please feel free to correct me if I'm wrong. 2) CGI.pm returns a string with an original full path/filename on client's computer when $filename is used as a string. If it's used as a file handle, a file handle is returned 3) you can get the MIME type of the uploaded file from CGI.pm. but if you want to be sure 100%, let's say, .gif is a gif actually, .jpg is a JPEG, you should check the file's content using 'file' utility thru a system call or an image-processing library like PerlMagick (ImageMagick). But it goes far away from the original question