Jump to content

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/247200-undefined-index-notice-plus-more/
Share on other sites

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.

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.

 

 

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.

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>";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.