Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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

704 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