Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Uploading pictures - displays only 2 of 12

by libuska78 (Initiate)
on Oct 16, 2009 at 23:39 UTC ( [id://801681]=perlquestion: print w/replies, xml ) Need Help??

libuska78 has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

my problem is quite odd and gives me a real headache for more than a week. I have a auction website script with picture upload (it is not my script, I am just working with it) http://www.sablonyproweb.cz/cgi-bin/auction/upload.cgi where you are supposed to upload 12 pictures. You should see them underneath when uploaded. What happens:

all of them will upload into the upploaddirectory but: if you upload 2 of them (1st plus any of others), they will appear on the site and everything runs ok

if you upload 3 and more, nothing will happen (even if they appear in the right directory on FTP)

There is no settings in auction website that would allow customers to upload just certain amount of pictures. Size is naturally limited, but if you go over the limit, the system will tell you.

Because I suppose that the error must be in sub upload, I copy here this code

sub upload { if ($match){ print "<table align=center width=100% border=0 cellspacing +=0 cellpadding=0>"; print "<tr><td align=center width=100%>"; print "<FORM ACTION=\"$config{'scripturl'}/cgi-bin/auction +/auction.cgi?action=uploaddone\&IMAGE1=$file1\" METHOD=POST>"; if ($file1){ print "<center><b><font face=arial size=2>Image file 1:</b +>: $file1</center>\n"; print "<center><font face=arial size=2>$uploadfile1 <br><b +>Upload Complete Image 1.</b></font></center>\n"; print "<p><img src=$config{'imageuploadurl'}/$file1></p><h +r width=80% size=1 color=$config{'bordercolor'}>\n"; } if ($file2){ print "<center><b><font face=arial size=2>Image file 2:</b +>: $file2</center>\n"; print "<center><font face=arial size=2>$uploadfile2 <br><b +>Upload Complete Image 2.</b></font></center>\n"; print "<p><img src=$config{'imageuploadurl'}/$file2></p><h +r width=80% size=1 color=$config{'bordercolor'}>\n"; } if ($file3){ print "<center><b><font face=arial size=2>Image file 3:</b +>: $file3</center>\n"; print "<center><font face=arial size=2>$uploadfile3 <br><b +>Upload Complete Image 3.</b></font></center>\n"; print "<p><img src=$config{'imageuploadurl'}/$file3></p><h +r width=80% size=1 color=$config{'bordercolor'}>\n"; } if ($file4){ print "<center><b><font face=arial size=2>Image file 4:</b +>: $file4</center>\n"; print "<center><font face=arial size=2>$uploadfile4 <br><b +>Upload Complete Image 4.</b></font></center>\n"; print "<p><img src=$config{'imageuploadurl'}/$file4></p><h +r width=80% size=1 color=$config{'bordercolor'}>\n"; } if ($file5){ print "<center><b><font face=arial size=2>Image file 5:</b +>: $file5</center>\n"; print "<center><font face=arial size=2>$uploadfile5 <br><b +>Upload Complete Image 5.</b></font></center>\n"; print "<p><img src=$config{'imageuploadurl'}/$file5></p><h +r width=80% size=1 color=$config{'bordercolor'}>\n"; } if ($file6){ print "<center><b><font face=arial size=2>Image file 6:</b +>: $file6</center>\n"; print "<center><font face=arial size=2>$uploadfile6 <br><b +>Upload Complete Image 6.</b></font></center>\n"; print "<p><img src=$config{'imageuploadurl'}/$file6></p><h +r width=80% size=1 color=$config{'bordercolor'}>\n"; } if ($file7){ print "<center><b><font face=arial size=2>Image file 7:</b +>: $file7</center>\n"; print "<center><font face=arial size=2>$uploadfile7 <br><b +>Upload Complete Image 7.</b></font></center>\n"; print "<p><img src=$config{'imageuploadurl'}/$file7></p><h +r width=80% size=1 color=$config{'bordercolor'}>\n"; } if ($file8){ print "<center><b><font face=arial size=2>Image file 8:</b +>: $file8</center>\n"; print "<center><font face=arial size=2>$uploadfile8 <br><b +>Upload Complete Image 8.</b></font></center>\n"; print "<p><img src=$config{'imageuploadurl'}/$file8></p><h +r width=80% size=1 color=$config{'bordercolor'}>\n"; } if ($file9){ print "<center><b><font face=arial size=2>Image file 9:</b +>: $file9</center>\n"; print "<center><font face=arial size=2>$uploadfile9 <br><b +>Upload Complete Image 9.</b></font></center>\n"; print "<p><img src=$config{'imageuploadurl'}/$file9></p><h +r width=80% size=1 color=$config{'bordercolor'}>\n"; } if ($file10){ print "<center><b><font face=arial size=2>Image file 10:</ +b>: $file10</center>\n"; print "<center><font face=arial size=2>$uploadfile10 <br>< +b>Upload Complete Image 10.</b></font></center>\n"; print "<p><img src=$config{'imageuploadurl'}/$file10></p>< +hr width=80% size=1 color=$config{'bordercolor'}>\n"; } if ($file11){ print "<center><b><font face=arial size=2>Image file 11:</ +b>: $file11</center>\n"; print "<center><font face=arial size=2>$uploadfile11 <br>< +b>Upload Complete Image 11.</b></font></center>\n"; print "<p><img src=$config{'imageuploadurl'}/$file11></p>< +hr width=80% size=1 color=$config{'bordercolor'}>\n"; } if ($file12){ print "<center><b><font face=arial size=2>Image file 12:</ +b>: $file12</center>\n"; print "<center><font face=arial size=2>$uploadfile12 <br>< +b>Upload Complete Image 12.</b></font></center>\n"; print "<p><img src=$config{'imageuploadurl'}/$file12></p>< +hr width=80% size=1 color=$config{'bordercolor'}>\n"; } if ($file1){ print "<input type=hidden name=IMAGE1 value=$file1>"; print "<input type=hidden name=THUMB1 value=$file1>"; } if ($file2){ print "<input type=hidden name=IMAGE2 value=$file2>"; } if ($file3){ print "<input type=hidden name=IMAGE3 value=$file3>"; } if ($file4){ print "<input type=hidden name=IMAGE4 value=$file4>"; } if ($file5){ print "<input type=hidden name=IMAGE5 value=$file5>"; } if ($file6){ print "<input type=hidden name=IMAGE6 value=$file6>"; } if ($file7){ print "<input type=hidden name=IMAGE7 value=$file7>"; } if ($file8){ print "<input type=hidden name=IMAGE8 value=$file8>"; } if ($file9){ print "<input type=hidden name=IMAGE9 value=$file9>"; } if ($file10){ print "<input type=hidden name=IMAGE10 value=$file10>"; } if ($file11){ print "<input type=hidden name=IMAGE11 value=$file11>"; } if ($file12){ print "<input type=hidden name=IMAGE12 value=$file12>"; } print "</td></tr></table>"; print "<center><p><font face=arial size=2>If the image(s) +are correct. Click \"Continue\".</font></center></p>"; print "<center><p><font face=arial size=2><font face=arial + size=2>If they are not correct, use your browsers back button to try + again.</font></center></p>"; print "<center><input type=submit value=\"Continue\"></cen +ter>"; print "</form>"; } }

It would be a real relieve if anybody has an idea what can cause this... Thank you so much for this site and opportunity to ask questions.

Replies are listed 'Best First'.
Re: Uploading pictures - displays only 2 of 12
by roboticus (Chancellor) on Oct 17, 2009 at 15:53 UTC
    libuska78:

    I don't see anything obvious to cause the problem you're seeing. However, after looking over the code, I don't think your error is in that subroutine1. It's hard to check, though, as the code is hard to look at, due to all the repetition.

    If you see the same thing happening over and over in your code, it's a sign that something's wrong. You don't want to do that, because it's hard to look over and be certain that you made the correct edit in each and every block. Instead, use a loop to do the work. That way, you can concentrate on getting the task correct with only a little loop overhead rather than copy and pasting the code over and over, and then making small hand edits to adjust filenames and such.

    Here's a rework of your subroutine that outputs the same text as yours, but rather than using hardcoded variables $file1, $file2, ... $file12, $uploadfile1, ..., $uploadfile12, it uses two arrays: @files and @uploadfiles:

    sub upload { if ($match){ print "<table align=center width=100% border=0 cellspacing=0 c +ellpadding=0>"; print "<tr><td align=center width=100%>"; print "<FORM ACTION=\"$config{'scripturl'}/cgi-bin/auction/auc +tion.cgi?action=uploaddone\&IMAGE1=$files[0]\" METHOD=POST>"; my $footer=''; for my $idx (0 .. $#files) { last if $idx > 11; ### Original code had 12 copies of the +same code... my $idx_n = $idx+1; print "<center><b><font face=arial size=2>Image file $idx_ +n:</b>: $files[$idx]</center>\n"; print "<center><font face=arial size=2>$uploadfiles[$idx] +<br><b>Upload Complete Image $idx_n.</b></font></center>\n"; print "<p><img src=$config{'imageuploadurl'}/$files[$idx]> +</p><hr width=80% size=1 color=$config{'bordercolor'}>\n"; $footer .= "<input type=hidden name=IMAGE$idx_n value=$fil +es[$idx]>"; if ($idx == 0) { ### Original code only created THUMB for first file... $footer .= "<input type=hidden name=THUMB$idx_n value= +$files[$idx]>"; } } print $footer; print "</td></tr></table>"; print "<center><p><font face=arial size=2>If the image(s) are +correct. Click \"Continue\".</font></center></p>"; print "<center><p><font face=arial size=2><font face=arial siz +e=2>If they are not correct, use your browsers back button to try aga +in.</font></center></p>"; print "<center><input type=submit value=\"Continue\"></center> +"; print "</form>"; } }

    There are other cleanups you can make, but I stopped at rolling your code up into a loop.

    ...roboticus

    Update: Added this footnote:

    1: Unless the problem is related to the THUMB input field being missing from items 2 through 12.

Re: Uploading pictures - displays only 2 of 12
by stonecolddevin (Parson) on Oct 17, 2009 at 21:43 UTC

    Check out SWFUpload for multifile uploads as well.

    mtfnpy

      Adding SWFUpload generates more dependencies: You need both Javascript and Flash available and enabled on the client (installing NoScript usually disables both, and Flash is not available for all platforms), and you need CSS available and enabled on the client unless you really want to confuse the user. And unless you want to really nag and confuse your user, you need a working fallback strategy using classic HTML forms and file upload fields. So, you also have to make your server side code more complex.

      I've discussed this over and over again, and unless you have a VERY controlled environment where users have to use a selected client program with a configuration that the users cannot change, tools like SWFUpload that require Javascript and plugins but do not offering working fallback code just do not work. Stick to plain HTML and use Javascript only to enhance existing features and there will be no such problems.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Uploading pictures - displays only 2 of 12
by libuska78 (Initiate) on Oct 17, 2009 at 20:58 UTC
    Hi, thank you very much for your time and reply! I have tried yoor shorter script and added all the thumbnails but it has still the same effect. There would be maybe something wrong with the form processing itself, but I cannot understand why two are working (even if you select 1. and 5. file) and not more together. This is how it starts:

    EOF @ext = qw(jpg gif bmp); $| = 1; $match = 0; $encoding = 'multipart/form-data'; $q = new CGI; print "Content-type: text/html\n\n"; print $config{'header2'}; print "<div align=center><center><table border=0 cellpadding=0 cellspa +cing=0 width=100% bordercolor=$config{'bordercolor'}>"; print "<tr><td width=100% bgcolor=$config{'colortablehead'} height=30> +<b>&nbsp;Select your pictures to upload ( @ext )</b></td></tr></table +></center></div><br>";

    then there is the form and under that:

    print "<hr width=80% size=1 color=$config{'bordercolor'}>"; print "<center><p><font face=arial size=2>Please click the \"Image Upl +oad\" button only once,<br>Image Upload can take up to 10 seconds per + image uploaded.<br>Your images will appear below when finished.</fon +t></center></p>"; print "<hr width=80% size=1 color=$config{'bordercolor'}>"; umask(000); mkdir("$config{'imageuploaddir'}", 0777) unless (-d "$config{'imageupl +oaddir'}"); $file1 = $form{'upload_file1'}; $file2 = $form{'upload_file2'}; $file3 = $form{'upload_file3'}; $file4 = $form{'upload_file4'}; $file5 = $form{'upload_file5'}; $file6 = $form{'upload_file6'}; $file7 = $form{'upload_file7'}; $file8 = $form{'upload_file8'}; $file9 = $form{'upload_file9'}; $file10 = $form{'upload_file10'}; $file11 = $form{'upload_file11'}; $file12 = $form{'upload_file12'}; $uploadfile1 = $q->param('upload_file1'); $uploadfile2 = $q->param('upload_file2'); $uploadfile3 = $q->param('upload_file3'); $uploadfile4 = $q->param('upload_file4'); $uploadfile5 = $q->param('upload_file5'); $uploadfile6 = $q->param('upload_file6'); $uploadfile7 = $q->param('upload_file7'); $uploadfile8 = $q->param('upload_file8'); $uploadfile9 = $q->param('upload_file9'); $uploadfile10 = $q->param('upload_file10'); $uploadfile11 = $q->param('upload_file11'); $uploadfile12 = $q->param('upload_file12'); if ($ENV{'CONTENT_LENGTH'} >= $config{'imagesize'} * 1024) { print "<p><div align=center><font face=arial size=2 color=FF +0000><p>Error - The image file size is too large\!</font></p>\n"; print "<p><font face=arial size=2>Sorry but your upload imag +e size can not be over $config{'imagesize'}kb.</font></p>\n"; print "<p><font face=arial size=2>Please only upload images +with a file size less than $config{'imagesize'}kb.</font></p></div>"; exit 0; } if ($uploadfile1){ $uploadfile1 =~ /\w:[\\[\w- ]*\\]*([\w- ]*.\w{1,3})$/g; $file1 = $1; foreach $ext (@ext){ if (grep /$ext$/i,$uploadfile1){ $match = 1; $type = $ext; } } if ($match){ $newimage = ($config{'closedays2'} * 86400 + time); $file1 = "$newimage.$type"; undef $bytesread; open(OUTFILE, ">$config{'imageuploaddir'}/$file1")||&error("Ca +n not open $config{'imageuploaddir'}/$file1. $!"); binmode OUTFILE; while ($bytesread=read($uploadfile1,$buffer,1024)) { print OUTFILE $buffer; } close (OUTFILE); sleep 2; # Wait 2 seconds } else { &error("<center><font face=arial size=2><b>Image forma +t not supported.</b><p>$uploadfile1</p><b>Upload has failed.</b></fon +t></center>"); } }

    And continues the same script for all 12 of them

    I am seriously willing to pay somebody's time to help me solve this hell. Thank you

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://801681]
Approved by planetscape
Front-paged by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-19 16:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found