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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
jsatterlCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.