Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how does CGI handle uploaded files

Status
Not open for further replies.

bobbybobbertson

Programmer
Nov 9, 2001
119
US
Can someone tell me how CGI handles uploaded files? Before the uploaded file is used by the perl script, does CGI store the file in memory, a temporary directory, where?

Also, is there a way to stop the upload if it gets too big? I have seen lots of scripts that limit the file size, but the limit happens after the file has been uploaded. In other words, if the limit is set to 1KB and someone uploads a 5MB file, all 5MB of the file is uploaded, then the script tests for the file size, and if it is too big, it deletes it. This is not good, as someone can still upload a really big file and waste server time and space.

Also, what does CGI do if the connection is lost? If someone stops the browser in the middle of uploading, does CGI delete the file? Or does it sit in some temporary directory somewhere?

thanks
 
Code:
# need acces to temp
# need this in <form> tag
# ENCTYPE='multipart/form-data' method='post'

print &quot;Content-type: text/html\n\n&quot;;
# filename
$fileSmall=param('zpictureSmall');
if ($fileSmall ne &quot;&quot;) {
  my $tmpfile=tmpFileName($fileSmall);
  $type_fichier=uploadInfo($fileSmall)->{'Content-Type'};
  while (<$fileSmall>) {
    $length += length($_);
  }
  sysseek($fileSmall,0,0);
}
# here copy from temp where u want
copy_tmpfile($fileSmall,&quot;$pt_upload/$zfilenameSmall&quot;);
close $fileSmall;

sub copy_tmpfile {
 my ($source,$destination) = @_;
 open (FILE2,&quot;>$destination&quot;);
 binmode(FILE2);
 while (!eof($source)) {
   $ligne=<$source>;
   print FILE2 ($ligne);
 }
 close (FILE2);
}
---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
I don't understand this code. Is this the code to stop the upload of a file if it is too large.

There seems to be some functions missing.
what do these do:
tmpFileName();
uploadInfo(;

 
There are a couple of faqs. See section 10 under the faqs tab. 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top