Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding more uploads to this script

Status
Not open for further replies.

Wulfgen

Technical User
Dec 31, 2004
283
US
I have a working cgi that allows registered users to upload files (one at a time) however, due to demands from the same users - I need to add multiple upload fi
elds to this

this is my form
Code:
<FORM ACTION="uploadmax.cgi" METHOD="post" ENCTYPE="multipart/form-data">
        <div align="center" class="style1">
          <div align="center">File 1 to Upload:
          <INPUT TYPE="file" NAME="photo">
          <br>
          <br>
          File 2 to Upload: 
		  <INPUT TYPE="file" NAME="photo1">
          <br>
          <br>
		  File 3 to Upload: 
		  <INPUT TYPE="file" NAME="photo2">
          <br>
          <br>
		  File 4 to Upload: 
		  <INPUT TYPE="file" NAME="photo3">
          <br>
          <br>
		  File 5 to Upload: 
		    <INPUT TYPE="file" NAME="photo4">
          <br>
          <br>
	   		File 6 to Upload: 
            <INPUT TYPE="file" NAME="photo5">
            <br>
            <br>
            Your Email Address: 
          <INPUT TYPE="text" NAME="email_address">
          <br>
          <INPUT TYPE="submit" NAME="Submit" VALUE="Upload File">
          </div>
        </div>
      </FORM>

and in my cgi - (I have only posted the necessary parts, otherwise its a little long) this:
Code:
use CGI;

$upload_dir = "/home/httpd/mysite.com/uploadedfiles/"; 
$http_upload_dir = "[URL unfurl="true"]http://www.mysite.com/uploadedfiles";[/URL]

$query = new CGI;

$filename = $query->param("photo");
$email_address = $query->param("email_address");
$filename =~ s/.*[\/\\](.*)/$6/;
$upload_filehandle = $query->upload("photo");

open UPLOADFILE, ">$upload_dir/$filename";

while ( <$upload_filehandle> )
{
  print UPLOADFILE;
}

close UPLOADFILE;


$sendmail = '/usr/lib/sendmail -t';
open MAIL, "|$sendmail";
print MAIL "To: me\@mysite.com\r\n";
print MAIL "From: website\r\n";
print MAIL "Subject: New file uploaded/posted\r\n\r\n";
print MAIL "A new file was uploaded to the FTP area\r\rfrom $email_address\n\rThe Filename is: $filename\r\n\r      Open/Download the file from here:\n\r\n      img src='$http_upload_dir/$filename'";
close MAIL;

Am I screwing up on the ($filename) and the ($upload_filehandle)?? Should i have them in some kind of array? to match the form field Names?

or am I totally off base?? or kinda whacked out......
 
Yes you should put them in an array and loop through them.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
or.. you can do
for my $num (1..6) {
if ($query->param("photo$num")){
$filename = $query->param("photo$num");
blah blha
}
}

as long as you make sure all your form names are photo1 photo2 photo3 etc..


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
OK so I'm really a dumb a...s here - the syntax is exactly...?

the blah blah got me and also the (1..6)

sorry :-(
 

well blah blah is the rest of your script..
(1..6) will loop through each number
so if you do
for my $num (1..6) {
print "$num\n";
}

you'll see what it does.
The other problem you have (that I can see) is that your files are going to be overwritten every time someone else does a upload. Maybe add $email_address as part of the name or something? In this example I'm going to prepend it with epoch.

I think your code should be like
Code:
my $epochtime = time;
for my $num (1..6) {
$filename = $query->param("$epochtime - photo$num");
$email_address = $query->param("email_address");
$filename =~ s/.*[\/\\](.*)/$6/;
$upload_filehandle = $query->upload("photo$num");

open UPLOADFILE, ">$upload_dir/$filename";

while ( <$upload_filehandle> )
{
  print UPLOADFILE;
}

close UPLOADFILE;

$sendmail = '/usr/lib/sendmail -t';
open MAIL, "|$sendmail";
print MAIL "To: me\@mysite.com\r\n";
print MAIL "From: website\r\n";
print MAIL "Subject: New file uploaded/posted\r\n\r\n";
print MAIL "A new file was uploaded to the FTP area\r\rfrom $email_address\n\rThe Filename is: $filename\r\n\r      Open/Download the file from here:\n\r\n      img src='$http_upload_dir/$filename'";
close MAIL;
}

not tested.. at all.. even a little bit

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
It doesnt seem to matter what configuration I try it doesnt work - I also tried it with the time epoch removed - nope - tried it with a single upload and time attached - nope -

I get a misconfiguration or script error or it just sits there and does 0
 
Do you know of a cgi based multiple file uploader with notification that I may look at?
 
Have you actually ran if via perl cli?? If not look at the error logs in your webserver. I'm sure you can find a script via google or check out cpan.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top