Uploading File

How can i check whether user did specify a file b4 clicking "Upload"? im not using any client-side scripting, so im using perl to check at the server end.

$ret = &ReadParse(\%cgi_data,\%cgi_cfn,\%cgi_ct,\%cgi_sfn);

this gave me a temp file everytime i click on upload .. even though the user did not specify any file to upload.

i also need to prompt user if the file they specify does not exist at all. Thanks!
irene79Asked:
Who is Participating?
 
jsatterlConnect With a Mentor Commented:
The following code will only work if you have the CGI.pm module installed:

use strict;
use CGI;

###############################################################################
$CGI::POST_MAX=1024 * 50;   # restrict file size to 50k

### create the cgi object
my $cgi_handle = new CGI;

# grab the cgi variables
my $file = $cgi_handle->param('file'); ## the filename on the user's computer
my $tmp_file = tmpFileName($file);
   
unless ($file) {
  print "You need to specify a file";
}  

if (-s $tmp_file) {
  print "The file you specified is empty";
}  

Hope this helps...
0
 
jsatterlCommented:
Your questions are a bit vague, but I will try to answer the best I can.

I am assuming that you are talking about using the FILE input form type.

Let's say you have the following html form input tag:
<input type=file name=upload_file>

In you perl script if you check for
the existense of the upload_file paramter, you can tell if any file name was entered.  You can also do a -s on the temp filename in an if statement to find out if the uploaded file has a size greater than zero.

That should cover both of your questions.
0
 
irene79Author Commented:
ermm can i have the exact code please?
0
All Courses

From novice to tech pro — start learning today.