pip has asked for the wisdom of the Perl Monks concerning the following question:
zentara wrote: Here this upload script might suit your purpose. I'll leave it up to you to add the filtering for gif, and jpgs. It should be obvious where it goes.
#!/usr/bin/perl -wT use strict; use CGI; my $q = new CGI; #The max size of the uploaded file: $CGI::POST_MAX = 1024 * 1024 * 30; my $maxfile = $CGI::POST_MAX; #The folder with the uploaded files: my $outfolder = "uploads"; &upload; ####################################################### sub upload { my ($filen, $ext); #Print the start of the page: $| = 1; print <<eof; Content-type: text/html Uploading the file... <body><html> eof my $file = $q->upload('file'); my $filename = $file; $filename =~ s/^.*\///g; $filename =~ s/^.*\\//g; $filename =~ s/\-/_/g; $filename =~ s/^\.*//g; $filename =~ s/ /_/g; my $allpath = $file; if ($filename =~ /\./) { $filen = $`; $ext = $'; } my $maxtries=4; for (my $i=1; $i < $maxtries; $i++) { if (-e "$outfolder/$filename") { $filename = $filen . "_" . $i . '.' . $ext; } } #Create the file on the server, and print the "." on the page: open(OUT, ">$outfolder/$filename") or die "Can't open $outfolder/$file for writing. - $!"; binmode OUT; while(read($file, my $buffer, 4096)){; print OUT $buffer; } close OUT; my $filesize = -s "$outfolder/$filename"; $filesize = (int(($filesize / 1024) * 10) / 10); $filesize = "$filesize KB"; #Print on the browser: my $script = 'http://zentara.zentara.net/~zentara/up2.html'; print <<eof; <br><br> The file $filename was successfully uploaded!<br> The file has $filesize.<br> <div class="center"> <a href="$script">Go back if you want to upload one more file.</a> <a href="http://zentara.zentara.net/~zentara">Go to home page!</a> </body></html> eof #End the subroutine }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: help,my upload script is bugged part 2
by zentara (Cardinal) on Aug 12, 2002 at 12:42 UTC | |
|
Re: help,my upload script is bugged part 2
by Anonymous Monk on Aug 12, 2002 at 15:00 UTC | |
|
Re: help,my upload script is bugged part 2
by pip (Novice) on Aug 13, 2002 at 11:33 UTC |