in reply to upload.cgi my script is bugged
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: Re: upload.cgi my script is bugged
by Anonymous Monk on Aug 12, 2002 at 01:30 UTC | |
|
Re: Re: upload.cgi my script is bugged
by pip (Novice) on Aug 12, 2002 at 02:53 UTC |