
mhx
Enthusiast
/ Moderator
Aug 30, 2001, 10:38 AM
Post #4 of 6
(499 views)
|
|
Re: Uploading Files - PROBLEM!
[In reply to]
|
Can't Post
|
|
Now I know what you're trying to do. For this, the CGI modules are sufficient, no Net::FTP required. If you want to know more about Net::FTP, follow the link to CPAN in my last post. Your code doesn't look too bad to me. I can only spot some missing quotes around the $dir string and the regex part looks a bit strange, but still ok. Perhaps this helps, it's a script I've written a long time ago (I don't even remember the password I need...) which accepts file uploads. Most of the scripts is only checking if this is a valid upload, and the script isn't that nice, but it mainly serves the same purpose as yours. Perhaps you can spot a problem if you compare it with your original code.
#!/usr/bin/perl -w use CGI qw(-no_debug :standard); use CGI::Carp qw(fatalsToBrowser); use strict; sub fail ($) { print header, start_html('FAIL:'.shift()), end_html; exit } if( param() && param('action') && param('passwd') && crypt( param('passwd'), '00' ) eq '00PQjU5U6Vi4.' ) { if( param('action') eq 'upload' ) { my %files = ( info => { type => 'text/plain', loc => "i" }, hist => { type => 'image/gif', loc => "../p/h" }, lores => { type => 'image/.?jpeg', loc => "../p/lo" }, hires => { type => 'image/.?jpeg', loc => "../p/hi" }, ); my $fail; foreach( keys %files ) { $fail = 1; last unless param($_); last unless uploadInfo(param($_))->{'Content-Type'} =~ /$files{$_}{type}/; $fail = 0; } unless( $fail ) { local $/ = undef; my $root = $ENV{DOCUMENT_ROOT}; $root =~ s/\/(?:www|cgi|cgi-bin)$//; foreach( keys %files ) { my $file = param($_); my $path = "$files{$_}{loc}/" . ($file =~ /([^:\/\\]+)$/)[0]; open OUT, ">$path" or fail "cannot open '$path': $!"; binmode OUT; binmode $file; print OUT <$file>; close OUT; } print header, start_html('SUCCEED'), end_html; } } } -- Marcus
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= ($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"
|