lars55 Posted September 15, 2011 Share Posted September 15, 2011 I realize others have had problems with the undefined index issue, but I can't find any answer to my particular problem in any forum, anywhere. I have a form/script which uploads images with description for an artist site. There are 25 images available to upload (an artist profile image and 24 art images), and the images 1-19 upload just fine. All the images share exactly the same code. But when the processing script comes to image 20, it fails and I get the "undefined index" notice. Here is the processing code for image 19-20. //There are a total of 20 other blocks of code above this one, //and they are all the same except for the image number. //Artimage19 Process Begin $artimage19 = $_FILES['artimage19']['name']; $file_size = $_FILES['artimage19']['size']; $file_temp = $_FILES['artimage19']['tmp_name']; $title19 = $_POST['title19']; $disptitle19 = stripslashes($title19); $medium19 = $_POST['medium19']; $dim19 = $_POST['dim19']; $price19 = $_POST['price19']; $file_basename = substr($artimage19, 0, strripos($artimage19, '.')); // strip extention $file_ext = substr($artimage19, strripos($artimage19, '.')); $allowed_extensions['ext']= array('jpeg','jpg','gif','png'); if(!$allowed_extensions){ echo "Artimage19 file extension not allowed."; }else{ $file_ext = strtolower($file_ext); $random = rand(0000, 9999); $new_file_name19 = $surname.$random. '.' .$file_ext; } if($file_size > MAX_SIZE*1024) { echo 'ARTIMAGE19 FILE SIZE TO LARGE<BR />'; } if(move_uploaded_file($file_temp, "$filepath/$new_file_name19")) { //echo '<h3>Upload Successful!</h3>'; } else { echo '<h3>ERROR IN UPLOADING ARTIMAGE19</h3>'; } //Artimage19 Process Ends //Artimage20 Process Begin $artimage20 = $_FILES['artimage20']['name']; $file_size = $_FILES['artimage20']['size']; $file_temp = $_FILES['artimage20']['tmp_name']; $title20 = $_POST['title20']; $disptitle20 = stripslashes($title20); $medium20 = $_POST['medium20']; $dim20 = $_POST['dim20']; $price20 = $_POST['price20']; $file_basename = substr($artimage20, 0, strripos($artimage20, '.')); // strip extention $file_ext = substr($artimage20, strripos($artimage20, '.')); $allowed_extensions['ext']= array('jpeg','jpg','gif','png'); if(!$allowed_extensions){ echo "Artimage20 file extension not allowed."; }else{ $file_ext = strtolower($file_ext); $random = rand(0000, 9999); $new_file_name20 = $surname.$random. '.' .$file_ext; } if($file_size > MAX_SIZE*1024) { echo 'ARTIMAGE20 FILE SIZE TO LARGE<BR />'; } if(move_uploaded_file($file_temp, "$filepath/$new_file_name20")) { //echo '<h3>Upload Successful!</h3>'; } else { echo '<h3>ERROR IN UPLOADING ARTIMAGE20</h3>'; } //Artimage20 Process Ends Artimage19 uploads just fine, but Artimage20 fails. The $filepath is set correctly, as it uploads all previous image files. The code for the submitting code is fine also. Here is the code that submits the data. //The form header is below <form action="pdregisterres.php" method="POST" enctype="multipart/form-data" onSubmit="return checkrequired(this)"> //there are 18 others above this plus one for an artist profile image <tr><td colspan = "2"><hr></td></tr> <tr><td align = "left">Art Image 19:</td><td align = "left"><input type = "file" name = "artimage19"></td></tr> <tr><td align = "left">Title:</td><td align = "left"><input type = "text" name = "title19"></td></tr> <tr><td align = "left">Medium:</td><td align = "left"><input type = "text" name = "medium19"></td></tr> <tr><td align = "left">Dimensions:</td><td align = "left"><input type = "text" name = "dim19"></td></tr> <tr><td align = "left">Price:</td><td align = "left"><input type = "text" name = "price19"></td></tr> <tr><td colspan = "2"><hr></td></tr> <tr><td align = "left">Art Image 20:</td><td align = "left"><input type = "file" name = "artimage20"></td></tr> <tr><td align = "left">Title:</td><td align = "left"><input type = "text" name = "title20"></td></tr> <tr><td align = "left">Medium:</td><td align = "left"><input type = "text" name = "medium20"></td></tr> <tr><td align = "left">Dimensions:</td><td align = "left"><input type = "text" name = "dim20"></td></tr> <tr><td align = "left">Price:</td><td align = "left"><input type = "text" name = "price20"></td></tr> For some reason that I can't get, the form stops processing after Artimage19 and gives me this: Notice: Undefined index: artimage20 in /home/www/artistsofeureka.info/members/pdregisterres.php on line 1046 I also get the error message: ERROR IN UPLOADING ARTIMAGE20 I get this for images 20-24. Since the code for all image processing is exactly the same (except for image #), I can't see why it stops at #19. These images are being uploaded to a folder on my server and a mysql db. Images up to #19 upload just fine. Any comments, questions or helpful advice? Quote Link to comment https://forums.phpfreaks.com/topic/247200-undefined-index-notice-plus-more/ Share on other sites More sharing options...
WebStyles Posted September 15, 2011 Share Posted September 15, 2011 I didn't look at your code, but could it be that you're reaching the allowed upload limit and the last 4 or 5 images are not being sent ? Quote Link to comment https://forums.phpfreaks.com/topic/247200-undefined-index-notice-plus-more/#findComment-1269615 Share on other sites More sharing options...
lars55 Posted September 15, 2011 Author Share Posted September 15, 2011 I realize others have had problems with the undefined index issue, but I can't find any answer to my particular problem in any forum, anywhere. I have a form/script which uploads images with description for an artist site. There are 25 images available to upload (an artist profile image and 24 art images), and the images 1-19 upload just fine. All the images share exactly the same code. But when the processing script comes to image 20, it fails and I get the "undefined index" notice. Here is the processing code for image 19-20. //There are a total of 20 other blocks of code above this one, //and they are all the same except for the image number. //Artimage19 Process Begin $artimage19 = $_FILES['artimage19']['name']; $file_size = $_FILES['artimage19']['size']; $file_temp = $_FILES['artimage19']['tmp_name']; $title19 = $_POST['title19']; $disptitle19 = stripslashes($title19); $medium19 = $_POST['medium19']; $dim19 = $_POST['dim19']; $price19 = $_POST['price19']; $file_basename = substr($artimage19, 0, strripos($artimage19, '.')); // strip extention $file_ext = substr($artimage19, strripos($artimage19, '.')); $allowed_extensions['ext']= array('jpeg','jpg','gif','png'); if(!$allowed_extensions){ echo "Artimage19 file extension not allowed."; }else{ $file_ext = strtolower($file_ext); $random = rand(0000, 9999); $new_file_name19 = $surname.$random.$file_ext; } if($file_size > MAX_SIZE*1024) { echo 'ARTIMAGE19 FILE SIZE TO LARGE<BR />'; } if(move_uploaded_file($file_temp, "$filepath/$new_file_name19")) { //echo '<h3>Upload Successful!</h3>'; } else { echo '<h3>ERROR IN UPLOADING ARTIMAGE19</h3>'; } //Artimage19 Process Ends //Artimage20 Process Begin $artimage20 = $_FILES['artimage20']['name']; $file_size = $_FILES['artimage20']['size']; $file_temp = $_FILES['artimage20']['tmp_name']; $title20 = $_POST['title20']; $disptitle20 = stripslashes($title20); $medium20 = $_POST['medium20']; $dim20 = $_POST['dim20']; $price20 = $_POST['price20']; $file_basename = substr($artimage20, 0, strripos($artimage20, '.')); // strip extention $file_ext = substr($artimage20, strripos($artimage20, '.')); $allowed_extensions['ext']= array('jpeg','jpg','gif','png'); if(!$allowed_extensions){ echo "Artimage20 file extension not allowed."; }else{ $file_ext = strtolower($file_ext); $random = rand(0000, 9999); $new_file_name20 = $surname.$random.$file_ext; } if($file_size > MAX_SIZE*1024) { echo 'ARTIMAGE20 FILE SIZE TO LARGE<BR />'; } if(move_uploaded_file($file_temp, "$filepath/$new_file_name20")) { //echo '<h3>Upload Successful!</h3>'; } else { echo '<h3>ERROR IN UPLOADING ARTIMAGE20</h3>'; } //Artimage20 Process Ends Artimage19 uploads just fine, but Artimage20 fails. The $filepath is set correctly, as it uploads all previous image files. The code for the submitting code is fine also. Here is the code that submits the data. //The form header is below <form action="pdregisterres.php" method="POST" enctype="multipart/form-data" onSubmit="return checkrequired(this)"> //there are 18 others above this plus one for an artist profile image <tr><td colspan = "2"><hr></td></tr> <tr><td align = "left">Art Image 19:</td><td align = "left"><input type = "file" name = "artimage19"></td></tr> <tr><td align = "left">Title:</td><td align = "left"><input type = "text" name = "title19"></td></tr> <tr><td align = "left">Medium:</td><td align = "left"><input type = "text" name = "medium19"></td></tr> <tr><td align = "left">Dimensions:</td><td align = "left"><input type = "text" name = "dim19"></td></tr> <tr><td align = "left">Price:</td><td align = "left"><input type = "text" name = "price19"></td></tr> <tr><td colspan = "2"><hr></td></tr> <tr><td align = "left">Art Image 20:</td><td align = "left"><input type = "file" name = "artimage20"></td></tr> <tr><td align = "left">Title:</td><td align = "left"><input type = "text" name = "title20"></td></tr> <tr><td align = "left">Medium:</td><td align = "left"><input type = "text" name = "medium20"></td></tr> <tr><td align = "left">Dimensions:</td><td align = "left"><input type = "text" name = "dim20"></td></tr> <tr><td align = "left">Price:</td><td align = "left"><input type = "text" name = "price20"></td></tr> For some reason that I can't get, the form stops processing after Artimage19 and gives me this: Notice: Undefined index: artimage20 in /home/www/artistsofeureka.info/members/pdregisterres.php on line 1046 I also get the error message: ERROR IN UPLOADING ARTIMAGE20 I get this for images 20-24. Since the code for all image processing is exactly the same (except for image #), I can't see why it stops at #19. These images are being uploaded to a folder on my server and a mysql db. Images up to #19 upload just fine. Any comments, questions or helpful advice? I made a correction in the code, but it is still not working. It is like it is not uploading the images 20-24. But uploads 1-19 just fine. As far as I know, I have not reached any upload limit. The upload file limit is set at 2mb. All 25 images together barely exceed 1mb. Quote Link to comment https://forums.phpfreaks.com/topic/247200-undefined-index-notice-plus-more/#findComment-1269624 Share on other sites More sharing options...
PFMaBiSmAd Posted September 15, 2011 Share Posted September 15, 2011 A) You should have used an array for the form field name and a simple loop in the php code to iterate over the images instead of copy/pasting/altering the code 25 times. You should have also dynamically produced the form using a loop instead of copy/pasting/altering the code 25 times. B) As to the problem - max_file_uploads 20 PHP_INI_SYSTEM Available since PHP 5.2.12. max_file_uploads integer The maximum number of files allowed to be uploaded simultaneously. Starting with PHP 5.3.4, upload fields left blank on submission do not count towards this limit. Quote Link to comment https://forums.phpfreaks.com/topic/247200-undefined-index-notice-plus-more/#findComment-1269626 Share on other sites More sharing options...
lars55 Posted September 15, 2011 Author Share Posted September 15, 2011 Thanks PFMaBiSmAd. Problem solved. When I originally looked at my php (5.2) on the server, I didn't see any place that addressed max_file_uploads. Only max_filesize_uploads. After doing the phpinfo.php view, I saw where it had a 20 upload limit. So I added max_file_uploads and set it to 25, and now, all is good. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/247200-undefined-index-notice-plus-more/#findComment-1269633 Share on other sites More sharing options...
PFMaBiSmAd Posted September 15, 2011 Share Posted September 15, 2011 As an added bonus, here is what your form code could be reduced to by using php to produce it (the form processing code would be similarly reduced) - <?php $fields = explode(',','Artist Profile Image,Art Image ' . implode(',Art Image ',range(1,24))); echo '<form action="pdregisterres.php" method="POST" enctype="multipart/form-data" onSubmit="return checkrequired(this)">'; echo "<table>"; foreach($fields as $key=>$field){ echo '<tr><td colspan = "2"><hr></td></tr>'; echo '<tr><td align = "left">'.$field.':</td><td align = "left"><input type = "file" name = "artimage['.$key.']"></td></tr>'."\n"; echo '<tr><td align = "left">Title:</td><td align = "left"><input type = "text" name = "title['.$key.']"></td></tr>'."\n"; echo '<tr><td align = "left">Medium:</td><td align = "left"><input type = "text" name = "medium['.$key.']"></td></tr>'."\n"; echo '<tr><td align = "left">Dimensions:</td><td align = "left"><input type = "text" name = "dim['.$key.']"></td></tr>'."\n"; echo '<tr><td align = "left">Price:</td><td align = "left"><input type = "text" name = "price['.$key.']"></td></tr>'."\n"; } echo "</table><input type='submit'></form>"; Quote Link to comment https://forums.phpfreaks.com/topic/247200-undefined-index-notice-plus-more/#findComment-1269634 Share on other sites More sharing options...
lars55 Posted September 15, 2011 Author Share Posted September 15, 2011 Thanks for the added bonus PFMaBiSmAd. My level of php expertise takes me only so far. I know for some, its child's play. I do what I can with what I know, and I do try to expand what I know. I appreciate your help. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/247200-undefined-index-notice-plus-more/#findComment-1269636 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.