tzeromn Posted April 9, 2011 Share Posted April 9, 2011 I am going kinda crazy. I'm a newby to php but I'm getting the hang of it. I'm having a problem with adding restrictions on multiple uploads. I want to make sure that they are "jpg" and "giff" only. and that they are not larger than 10 mb. can you help please. this is what i have. $path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0]; $path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1]; $path3= "upload/".$HTTP_POST_FILES['ufile']['name'][2]; copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1); copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2); copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3); echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>"; echo "<img src=\"$path1\" width=\"150\" height=\"150\">"; echo "<P>"; echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>"; echo "<img src=\"$path2\" width=\"150\" height=\"150\">"; echo "<P>"; echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>"; echo "<img src=\"$path3\" width=\"150\" height=\"150\">"; $filesize1=$HTTP_POST_FILES['ufile']['size'][0]; $filesize2=$HTTP_POST_FILES['ufile']['size'][1]; $filesize3=$HTTP_POST_FILES['ufile']['size'][2]; if($filesize1 && $filesize2 && $filesize3 != 0) { echo "We have received your files"; } else { echo "ERROR....."; } if($filesize1==0) <br /> { echo "There was something wrong with your first file"; echo "<BR />"; } if($filesize2==0) { echo "There was something wrong with your second file"; echo "<BR />"; } if($filesize3==0) { echo "There was something wrong with your third file"; echo "<BR />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233168-adding-restrictions-on-multiple-uploads/ Share on other sites More sharing options...
3raser Posted April 9, 2011 Share Posted April 9, 2011 I'm not exactly familiar with that type of upload script, but this might work: <?php if($HTTP_POST_FILES['ufile']['type'] != "image/gif" || $HTTP_POST_FILES['ufile']['type'] != "image/jpg") { echo "You've tried to upload a disallowed file type."; } else { echo "succes"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233168-adding-restrictions-on-multiple-uploads/#findComment-1199114 Share on other sites More sharing options...
tzeromn Posted April 9, 2011 Author Share Posted April 9, 2011 I am just going to change the script type. it throws me off as well, what I liked about it was that it showed me a thumbnail of the file after it was uploaded. with this line. echo "<img src=\"$path1\" width=\"150\" height=\"150\">"; but It's all a bit confusing. this script worked well when I was uploading one file and it only allowed jpgs and giffs which was perfect. except that it wasn't showing me a thumbnail. can you help me make this into a a script that uploads multiple files, and shows me a thumbnail like the previous one. here's the script that only allows me to upload one file at a time and under is the upload form I am using for multiple uploads: Thank you in advance. <?php if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"]; } ?> <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 10000000)) { if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"]; } } else { echo "Invalid file"; } ?> <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 10000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> // this is the upload file form that I am using <form action=" upload_file.php " method="post" enctype="multipart/form-data"> <strong>multiple Files Upload </strong> <br /> <label for =”file”>File 1:</label> <input type="file" name="file[]" id="file[]" size="50" /> </td> <br /> <label for =”file”>File 2:</label> <input type="file" name="file[]" id="file[]" size="50" /> </td> <br /> <label for =”file”>File 3:</label> <input type="file" name="file[]" id="file[]" size="50" /></td> <br /> <td align="left"><input type="submit" name="Submit" value="Upload" /></td> </form> Quote Link to comment https://forums.phpfreaks.com/topic/233168-adding-restrictions-on-multiple-uploads/#findComment-1199185 Share on other sites More sharing options...
ted_chou12 Posted April 9, 2011 Share Posted April 9, 2011 Although I havent seen this before: $HTTP_POST_FILES['ufile']['name'][0] (probably new), but I am sure its a post form variable and you didn't define it, post form variables are lost when you refresh your page somewhere, so you need to write down your filenames somewhere after you uploaded and then recall it after you refresh the page: <?php if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"]; } ?> <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 10000000)) { if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"]; } } else { echo "Invalid file"; } ?> <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 10000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; file_put_contents("log.txt", "upload/" . $_FILES["file"]["name"]);//saved here } } } else { echo "Invalid file"; } ?> // this is the upload file form that I am using <form action=" upload_file.php " method="post" enctype="multipart/form-data"> <strong>multiple Files Upload </strong> <br /> <label for =”file”>File 1:</label> <input type="file" name="file[]" id="file[]" size="50" /> </td> <br /> <label for =”file”>File 2:</label> <input type="file" name="file[]" id="file[]" size="50" /> </td> <br /> <label for =”file”>File 3:</label> <input type="file" name="file[]" id="file[]" size="50" /></td> <br /> <td align="left"><input type="submit" name="Submit" value="Upload" /></td> </form> $content = file_get_content("log.txt"); $path1= "$content"; $path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1]; $path3= "upload/".$HTTP_POST_FILES['ufile']['name'][2]; copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1); copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2); copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3); echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>"; echo "<img src=\"$path1\" width=\"150\" height=\"150\">"; echo "<P>"; echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>"; echo "<img src=\"$path2\" width=\"150\" height=\"150\">"; echo "<P>"; echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>"; echo "<img src=\"$path3\" width=\"150\" height=\"150\">"; $filesize1=$HTTP_POST_FILES['ufile']['size'][0]; $filesize2=$HTTP_POST_FILES['ufile']['size'][1]; $filesize3=$HTTP_POST_FILES['ufile']['size'][2]; if($filesize1 && $filesize2 && $filesize3 != 0) { echo "We have received your files"; } else { echo "ERROR....."; } if($filesize1==0) <br /> { echo "There was something wrong with your first file"; echo "<BR />"; } if($filesize2==0) { echo "There was something wrong with your second file"; echo "<BR />"; } if($filesize3==0) { echo "There was something wrong with your third file"; echo "<BR />"; } ?> [/code] I am not sure about some of the redundant code though. :/[/code] Quote Link to comment https://forums.phpfreaks.com/topic/233168-adding-restrictions-on-multiple-uploads/#findComment-1199189 Share on other sites More sharing options...
tzeromn Posted April 9, 2011 Author Share Posted April 9, 2011 Thank you so much it worked. Quote Link to comment https://forums.phpfreaks.com/topic/233168-adding-restrictions-on-multiple-uploads/#findComment-1199387 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.