CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
How to Upload Files"?

 



Karthik
Deleted

Dec 18, 2000, 3:17 AM

Post #1 of 2 (153 views)
How to Upload Files"? Can't Post

Hi all
Can any one tell me How to upload files using cgi??
Thanks in Advance
Karthik



Rivotti
User

Dec 18, 2000, 4:01 AM

Post #2 of 2 (151 views)
Re: How to Upload Files"? [In reply to] Can't Post

Hi Karthik,

This is how its done:

# In your html file use:

<FORM METHOD="POST" ACTION="yourcgi.cgi" ENCTYPE="multipart/form-data"> # Without the ENCTYPE tag it will not work
...
<INPUT TYPE="file" NAME="file_upload">
...
</FORM>

# In your CGI file

# get the file
$file_upload = param('file_upload');

# Get only the name of the file in the path
$file_upload =~ m!([^/:\\]*)$!;
my $short_name = $1;

my $size;

open (SAVE,">$short_name") || die $!;
while ($size = read($file_upload,$data,1024)) {
print SAVE $data;
}
close SAVE;

Rivotti




 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives