I am a fairly good web-designer but when it comes to programming I'm just a newbie (though I'm learning). I have this nice script, which uploads 3 files at a time, and when showing the results of the action also shows the small picture of each file (if images): Input: <form action="multiple_upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td align="center">Select the pictures:</td> </tr> <tr> <td align="center"> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center"> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <td align="center"> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center"><input type="submit" name="Submit" value="Upload" /></td> </tr> </table> </td> </form> ------------- Action: (multiple_upload_ac.php): <?php $path1= "upload/".$_FILES['ufile']['name'][0]; $path2= "upload/".$_FILES['ufile']['name'][1]; $path3= "upload/".$_FILES['ufile']['name'][2]; copy($_FILES['ufile']['tmp_name'][0], $path1); copy($_FILES['ufile']['tmp_name'][1], $path2); copy($_FILES['ufile']['tmp_name'][2], $path3); echo "<table><tr><td>"; echo "File Name :".$_FILES['ufile']['name'][0]."<BR/>"; echo "File Size :".$_FILES['ufile']['size'][0]."<BR/>"; echo "File Type :".$_FILES['ufile']['type'][0]."<BR/>"; echo "<img src=\"$path1\" width=\"150\" height=\"150\">"; echo "</td><td>"; echo "File Name :".$_FILES['ufile']['name'][1]."<BR/>"; echo "File Size :".$_FILES['ufile']['size'][1]."<BR/>"; echo "File Type :".$_FILES['ufile']['type'][1]."<BR/>"; echo "<img src=\"$path2\" width=\"150\" height=\"150\">"; echo "</td><td>"; echo "File Name :".$_FILES['ufile']['name'][2]."<BR/>"; echo "File Size :".$_FILES['ufile']['size'][2]."<BR/>"; echo "File Type :".$_FILES['ufile']['type'][2]."<BR/>"; echo "<img src=\"$path3\" width=\"150\" height=\"150\">"; echo "</td></tr></table>"; $filesize1=$_FILES['ufile']['size'][0]; $filesize2=$_FILES['ufile']['size'][1]; $filesize3=$_FILES['ufile']['size'][2]; if($filesize1 && $filesize2 && $filesize3 != 0) { echo "<br><b>Your picture(s) were successfully uploaded.<b>"; } else { echo "ERROR....."; } if($filesize1==0) { echo "There is an error with your 1st file"; echo "<BR />"; } if($filesize2==0) { echo "There is an error with your 2nd file"; echo "<BR />"; } if($filesize3==0) { echo "There is an error with your 3rd file"; echo "<BR />"; } ?> The problems: If I want to upload just 1 file, and I input the info in form box 1, it will output at the top of the results page: "Warning: copy() ['function.copy]: Filename cannot be empty in /home/........./multiple_upload_ac.php on line ..." twice, or if I want to upload just 2 files (form box 1 and 2) it will output this message once. This is the smaller problem, because I tried to solve it with a HTML hack like making the text so tiny that hardly can be observed. ( <body style="font-size:0.08em; line-height:0.1em"> ). But anyways would be nice to make the correct adjustment in the php code so no matter if I want to upload just 1 or 2 files, no error messages would come up at the top of the results page. The bigger problem: If I want to upload just 1 image file (filling just the 1st box of the input form), everything is fine, after the unwanted error messages at the top it shows nice the info about this file and it's small picture. But if I want to upload 2 image files (filling the first 2 boxes of the input form), in the first row (after the unwanted error message) shows the info and the small pic of the file 1, and in the 2nd rows again the info and small pic of file 1 plus the info of the file 2 and it's small image. (So file 1 will be in duplicate on the page....) If I want to upload 3 image files, in the first row (after the unwanted error message) shows the info and the small pic of the file 1, in the 2nd row again the info and small pic of file 1 plus the info of the file 2 and it's small image, and in the 3rd row again the infos and small pics for the files 1 and 2 plus the info and small pic of the file 3. (So file 1 will be in triplicate on the page, and file 2 in duplicate....) How can I modify the script so no matter how many images I want to upload the results page will show every info and small picture of the uploaded files just once? Another problem: I know how to limit the file types and file sizes, but just for a single file-upload script. I want to use this script to allow just jpg, pjpg and gif files to be uploaded, and the maximum file size to be 1024 kb, with the max total file size of 3072 kb. What I need to introduce in the script to reflect these limitations? ------------------- Thanks in advance for any help!
lol... you're welcome in advance... The biggest problem which you did not see: just give me the link to the page where you uploaded this script... i'll help you out
http://successteam.teamworkrevolution.com/upload/upload.html (I am not allowed to post a direct link )
<?php if(isset($_FILES['ufile']['name'][0])) $path1= "upload/".$_FILES['ufile']['name'][0]; if(isset($_FILES['ufile']['name'][1])) $path2= "upload/".$_FILES['ufile']['name'][1]; if(isset($_FILES['ufile']['name'][2])) $path3= "upload/".$_FILES['ufile']['name'][2]; if(isset($_FILES['ufile']['name'][0])) copy($_FILES['ufile']['tmp_name'][0], $path1); if(isset($_FILES['ufile']['name'][1])) copy($_FILES['ufile']['tmp_name'][1], $path2); if(isset($_FILES['ufile']['name'][2])) copy($_FILES['ufile']['tmp_name'][2], $path3); echo "<table><tr>"; if(isset($_FILES['ufile']['name'][0])) { echo"<td>"; echo "File Name :".$_FILES['ufile']['name'][0]."<BR/>"; echo "File Size :".$_FILES['ufile']['size'][0]."<BR/>"; echo "File Type :".$_FILES['ufile']['type'][0]."<BR/>"; echo "<img src=\"$path1\" width=\"150\" height=\"150\">"; echo "</td>"; } if(isset($_FILES['ufile']['name'][1])) { echo "<td>"; echo "File Name :".$_FILES['ufile']['name'][1]."<BR/>"; echo "File Size :".$_FILES['ufile']['size'][1]."<BR/>"; echo "File Type :".$_FILES['ufile']['type'][1]."<BR/>"; echo "<img src=\"$path2\" width=\"150\" height=\"150\">"; echo "</td>"; } if(isset($_FILES['ufile']['name'][2])) { echo "<td>"; echo "File Name :".$_FILES['ufile']['name'][2]."<BR/>"; echo "File Size :".$_FILES['ufile']['size'][2]."<BR/>"; echo "File Type :".$_FILES['ufile']['type'][2]."<BR/>"; echo "<img src=\"$path3\" width=\"150\" height=\"150\">"; echo "</td>"; } echo "</tr></table>"; $filesize1=$_FILES['ufile']['size'][0]; $filesize2=$_FILES['ufile']['size'][1]; $filesize3=$_FILES['ufile']['size'][2]; isdisp=0; if($filesize1!=0) { echo "<br><b>Your picture(s) were successfully uploaded.<b>"; $isdisp=1; } if($filesize2!=0 && $isdisp!=1) { echo "<br><b>Your picture(s) were successfully uploaded.<b>"; $isdisp=1; } if($filesize3!=0 && $isdisp!=1) { echo "<br><b>Your picture(s) were successfully uploaded.<b>"; $isdisp=1; } if($filesize1 && $filesize2 && $filesize3 != 0) { echo "<br><b>Your picture(s) were successfully uploaded.<b>"; } if ($isdisp==0;) { echo "ERROR....."; } /* Remove this if the code is working!! ////////////////////////////////////////////////////// if($filesize1==0) {/////////////////////////////////// echo "There is an error with your 1st file";////////// echo "<BR />";//////////////////////////////////////// }///////////////////////////////////////////////////// ////////////////////////////////////////////////////// if($filesize2==0) {/////////////////////////////////// echo "There is an error with your 2nd file";////////// echo "<BR />";//////////////////////////////////////// }///////////////////////////////////////////////////// ////////////////////////////////////////////////////// if($filesize3==0) {/////////////////////////////////// echo "There is an error with your 3rd file";////////// echo "<BR />";//////////////////////////////////////// }///////////////////////////////////////////////////// ////////////////////////////////////////////////////// */ ?> Code (markup): Try this bit and tell if it is working. Regards.
Thanks a lot! Now the table part is working fine, no double or triple outputs for some files, but still at the top of the page I get the error messages like: ""Warning: copy() ['function.copy]: Filename cannot be empty in /home/........./multiple_upload_ac.php on line .." if not all the upload boxes are filled before starting the upload. here I needed to correct: "...........$filesize1=$_FILES['ufile']['size'][0]; $filesize2=$_FILES['ufile']['size'][1]; $filesize3=$_FILES['ufile']['size'][2]; isdisp=0; if($filesize1!=0) { echo "<br><b>Your picture(s) were successfully uploaded.<b>"; $isdisp=1; }......" to $isdisp=0; otherwise it gave me script error. At the end of the script I needed to remove not only what you indicated, but also: "if ($isdisp==0); { echo "ERROR....."; }" , because otherwise if I upload less then 3 files, it will write at the end of page: "Your picture(s) were successfully uploaded.ERROR....." How about introducing the file size limitations and file type limitations?
extremely sorry, the code : should be there is a difference, although very small, the 'if' condition should not have a semicolon in it.
WOW, I saw that, but I just moved it outside the parenthesis. No need to excuse, because even if I'm a beginner in php I should know that after the "if" -s condition there is never a semicolon...
FINALLY: working only with images and restricted to 50 kb. all the possibilities now working perfectly. 3 cheers!! test it live at: http://test.vircafe.com here is the php code: Regards, Sunny Kumar Gupta