Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Perl CGI File Upload Problem

by nikhgeo (Initiate)
on Jun 20, 2011 at 09:23 UTC ( [id://910534]=note: print w/replies, xml ) Need Help??


in reply to Perl CGI File Upload Problem

I'm including the code, I've used :

fileupload.cgi

#!/usr/bin/perl print "Content-type: text/html\n\n"; print <<HTML; <html> <head> <title> File Upload Sample</title> </head> <body> <h1>Upload File</h2> <form action="fileprocess.cgi" method="post" enctype="multipart/fo +rm-data"> <input type="file" name="alertsfile" /> <input type="submit" value="Upload"> </form> </body> </html> HTML exit;

fileprocess.cgi

#!/usr/bin/perl-wT use strict; use CGI; use CGI::Carp qw (fatalsToBrowser); use File::Basename; $CGI::POST_MAX = 1024 * 5000; my $safe_filename_characters = "a-zA-Z0-9_.-"; my $upload_dir = "/home/netcool/alertfiles"; my $query = new CGI; my $filename = $query->param("alertsfile"); if ( !$filename ) { print $query->header ( ); print "There was a problem uploading your photo (try a smaller fil +e)."; exit; } my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' ); $filename = $name . $extension; $filename =~ tr/ /_/; $filename =~ s/[^$safe_filename_characters]//g; if ( $filename =~ /^([$safe_filename_characters]+)$/ ) { $filename = $1; } else { die "Filename contains invalid characters"; } my $upload_filehandle = $query->upload("alertsfile"); open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE; print $query->header ( ); print "Content-type: text/html\n\n"; print <<HTML; <html> <head> <title>Thanks</title> </head> <body> <p>Thanks for uploading your file!</p> <p>Your file:</p> <p><href src="/upload/$filename" alt="File" /></p> </body> </html> HTML

Replies are listed 'Best First'.
Re^2: Perl CGI File Upload Problem
by deMize (Monk) on Jul 30, 2014 at 20:17 UTC

      Looks awfully familiar to: http://www.sitepoint.com/uploading-files-cgi-perl-2/

      That url is listed in the OP, in Perl CGI File Upload Problem

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://910534]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found