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 do i upload files

 



lostChild
stranger

Feb 7, 2001, 7:46 AM

Post #1 of 4 (128 views)
how do i upload files Can't Post

can someone please tell me how i can upload files from a users harddisk/floppy onto a webserver by using a perl cgi program.... all i wish to do is to alow users to upload pictures onto my website so they can be seen my others........
help!



Jasmine
Administrator / Moderator

Feb 7, 2001, 10:51 AM

Post #2 of 4 (125 views)
Re: how do i upload files [In reply to] Can't Post

There's quite a few programs already available that perform file uploading. Check out http://perlarchive.com/guide/File_Uploading.

If you want to write your own, the best way to do it is via the CGI.pm modules.

Hope this helps!



lostChild
stranger

Feb 7, 2001, 11:17 AM

Post #3 of 4 (122 views)
Re: how do i upload files [In reply to] Can't Post

cgi.pm module? what is it and what do i do with it? sorry, i'm depressingly new to this........



Jasmine
Administrator / Moderator

Feb 7, 2001, 2:07 PM

Post #4 of 4 (117 views)
Re: how do i upload files [In reply to] Can't Post

CGI.pm is a Perl module that makes cgi work a snap. It includes most of the common functions, as well keeps creating actual html code in your Perl program very easy.

Describing CGI.pm completely (which actually has an entire published book on it) is an impossible feat.

Here's some sample code from the book for file uploading using CGI.pm (as published on http://www.wiley.com/compbooks/stein/text/upload.txt):


Code
#!/usr/bin/perl 
#file: upload.pl

use CGI qw/:standard/;

print header,
start_html('file upload'),
h1('file upload');
print_form() unless param;
print_results() if param;
print end_html;

sub print_form {
print start_multipart_form(),
filefield(-name=>'upload',-size=>60),br,
submit(-label=>'Upload File'),
end_form;
}

sub print_results {
my $length;
my $file = param('upload');
if (!$file) {
print "No file uploaded.";
return;
}
print h2('File name'),$file;
print h2('File MIME type'),
uploadInfo($file)->{'Content-Type'};
while (<$file>) {
$length += length($_);
}
print h2('File length'),$length;
}


 
 


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

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