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

x
?
Solved

Uploading file

Posted on 1999-08-18
5
Medium Priority
?
211 Views
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?
0
Comment
Question by:enots
[X]
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
5 Comments
 

Expert Comment

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

0
 

Author Comment

by:enots
ID: 1214969
how can i find that page
0
 
LVL 2

Expert Comment

by:mgaurav
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:
 http://www.cgi-resources.com

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

Accepted Solution

by:
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-
data">

<input type=file name=file>

</FORM>

In a cgi...
you can do

%data = &procesar;
this array contain then data of the form in the format
$data{fieldname};

# this return then content of the file.
$data{"file"};
# you can now know then filename
$data{"content_file"}{'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};
close(FILE);                  


# 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;
      }
      %datos;
}
0

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