Uploading file

Posted on 1999-08-18
Medium Priority
Last Modified: 2010-03-05
By using CGI, how can i do script for uploading file.. If anbody knows, I'd like to see some code that does that or show me some book or web pwge that related to this matter?  Or can someone just explain to me how  it's done?
Question by:enots

Expert Comment

ID: 1214968
try to look at the question on the same topic : Q_10192684.html


Author Comment

ID: 1214969
how can i find that page

Expert Comment

ID: 2057225
There are several scripts available on the net which are meant for file uploads. The best center for such and sevral other CGI scripts in perl and other languages is:

There you can find thousands of scripts, tens of them on File-Uploading

Accepted Solution

josesanch earned 200 total points
ID: 2250449
You need a form with encoded type multipart/form-data.... Like this.

<FORM ACTION="enviar.asp" METHOD="POST" name=formulario encType="multipart/form-

<input type=file name=file>


In a cgi...
you can do

%data = &procesar;
this array contain then data of the form in the format

# this return then content of the file.
# you can now know then filename

# to save the file...

 my (file) = $form{'content_file}{'filename'}=~ m{([^\\]*$)}; # Extract the name without the directory.

$file = $yourDir.$file;            
open(FILE, ">$file");
binmode(FILE);  # to save the data in binary mode..
print FILE $form{fichero};

# this Function return a hash with the data of the form.
sub procesar {            
      $ENV{'CONTENT_TYPE'} =~ m{multipart/form-data} || die "no es multipart/form-data";      
      my $texto, %datos, $in, $len;      
      $len  = $ENV{'CONTENT_LENGTH'};
      $texto = request;
      $in = $texto;            
      ($bound) = $in =~ m{(-*[^\s]*)}s;                  
      while ($texto=~ m{$bound(.*?)(?=$bound)}sg) {                        
            $campo = $1;            
            ($head, $content) = $campo =~ m{(.*?)\r\n\r\n(.*)\r\n}s;
            ($nombre) = $head =~ m{name="(.*?)"}i;            
            ($filename) = $head =~ m{filename="(.*?)"}i;            
            ($contenttype) = $head =~ m{Content-Type:\s*(.*)}i;
            $content =  $content if $filename eq "";
            $datos{$nombre} = $content;
            $datos{"content_$nombre"}{'content-type'} = $contenttype;
            $datos{"content_$nombre"}{'filename'} = $filename;

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question