Jump to content

[SOLVED] Why this error "Notice: Undefined index: "


lindylex

Recommended Posts

I keep getting this error "Notice: Undefined index: ".  I am trying to do something very simple.  Take some files submitted from a form for upload and save them to a certain theme directory.

 


<?php

$things_to_replace="/\s/";
$replace_with='_';

$path_of_folder=preg_replace ($things_to_replace, $replace_with ,$_POST["create_this_folder"]);

//Cleanup work because of IE 6
if (strlen($path_of_folder)!=0){
if ($path_of_folder[0]=='_'){
	$path_of_folder=substr ($path_of_folder,1);
}
}

if (strlen($_POST["create_this_folder"]) == 0){
	echo strlen($_POST["create_this_folder"])." << the length of form field create_this_folder <br>";
	echo "lllloookkk <br>";

	for ($i=0; $i<3; $i++){

			echo $_FILES ['uploadedfile']['tmp_name'][$i]." << temp name <br>";
			echo $_FILES ['uploadedfile']['name'][$i]." << original name <br>";
			echo $_FILES ['uploadedfile']['type'][$i]." << type <br>";
			echo $_FILES ['uploadedfile']['size'][$i]." << size<br>";


	}
}

?>

 

This is the error I receive  when I submit all three at once.  If I do two or less everything is fine, three kills it.  I have no idea.

 



Notice: Undefined index: create_this_folder in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 6

Notice: Undefined index: create_this_folder in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 15

Notice: Undefined index: create_this_folder in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 16
0 << the length of form field create_this_folder
lllloookkk

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 21
<< temp name

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 22
<< original name

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 23
<< type

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 24
<< size

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 21
<< temp name

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 22
<< original name

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 23
<< type

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 24
<< size

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 21
<< temp name

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 22
<< original name

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 23
<< type

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 24
<< size


 

Thanks, Lindylex

 

Link to comment
Share on other sites

Notice's can be ignored for operation - but not for good practice.

 

an Undefined index is where you are trying to use and Undefined array item (or index).

 

this is an example of an undefined index:

 

echo($arrayvariable['index']);

'index' is the index of the array.

 

$arrayvariable['index'] = "this index";
echo($arrayvariable['index']);

-------

Now you understand what the error means.

 

The error is caused by using this variable: $_POST["create_this_folder"] - it is saying this POSTED variable does not exist.

it is also saying that $_FILES ['uploadedfile'] does not exist.

---

 

what is the HTML source code of the form being submitted?

Link to comment
Share on other sites

uniflare,

 

The "$_POST["create_this_folder"] - it is saying this POSTED variable does not exist." it does exist.  It contains a value.  Ii works when I have two files selected but not three.

 

"$_FILES ['uploadedfile'] does not exist." this also exists but then dies when I try to upload three files.

 

uniflare, thanks for the help so far.

 

This the html form code.

 


<html>
<?php
function display_themes_in_drop_down($path ){
//Strip The Underscore Out
$things_to_replace="/_/";
$replace_with=' ';

//  Open  the  folder 
$dir_handle  =  opendir($path)  or  die("Unable  to  open  $path"); 
//  Loop  through  the  files 
while  ($file  =  readdir($dir_handle))  { 
	if ($file !='..' && $file !='.'){
		//echo  "$file<br>"; 
		$file= preg_replace ($things_to_replace, $replace_with ,$file);
		echo '<option>'.$file.'</option>';
	}
} 
//  Close 
closedir($dir_handle);
}
?>

<HEAD>
<SCRIPT language="JavaScript" SRC="../js/form_validation.js"></SCRIPT>
</HEAD> 

<title>:::Upload Your Image:::</title>
<body>


<!--<form enctype="multipart/form-data" name="stuff_to_upload" action="" onsubmit="return check_if_theme_exist (this);" method="post">-->
<form enctype="multipart/form-data" name="stuff_to_upload" action="create_del_folders.php" onsubmit="return check_if_theme_exist (this);" method="post">
<!--<form name="stuff_to_upload" onsubmit="return check_if_theme_exist (this);" method="post">-->

Choose a topic to upload to     Or    Create a topic to upload to<br> <br>

<select name="preview_themes" onChange = "limit_one_theme_only(this)">
	<option>Choose a theme</option>
	<?php display_themes_in_drop_down ("../photos");?>
</select>
                            
<input type="text" size = "20" name="create_this_folder" onKeyPress = "limit_one_theme_only_1(this)"/> <br><br>

<input type="hidden" name="MAX_FILE_SIZE" value="9000000" />
Choose files to upload:
<br><br>
<input type="hidden" name="MAX_FILE_SIZE" value="10240000" />

Downloadable<input type="checkbox" name="dl0">
	<select name="experation0">
	<!--<option>-------------------</option>-->
	<option>One Month</option>
	<option>Two Months</option>
	<option>Forever</option>
</select>

<input name="uploadedfile[]" type="file" /> 

<!--  Signature Photo<input type="checkbox" name="signature0" value="true"> -->
Color <input type="radio" name="borc0" value="c" >
B/W <input type="radio" name="borc0" value="b">


<br>

Downloadable<input type="checkbox" name="dl1">
	<select name="experation1">
	<!--<option>-------------------</option>-->
	<option>One Month</option>
	<option>Two Months</option>
	<option>Never</option>
</select>

<input name="uploadedfile[]" type="file" />

<!-- Signature Photo<input type="checkbox" name="signature1" value="true"> -->
Color <input type="radio" name="borc1" value="c" >
B/W <input type="radio" name="borc1" value="b">

<br>

  Downloadable<input type="checkbox" name="dl2">
	<select name="experation2">
	<!--<option>-------------------</option>-->
	<option>One Month</option>
	<option>Two Months</option>
	<option>Never</option>
</select>

<input name="uploadedfile[]" type="file"/>

<!-- Signature Photo<input type="checkbox" name="signature2" value="true"> -->
Color <input type="radio" name="borc2" value="c" >
B/W <input type="radio" name="borc2" value="b">

<br><br>
<input type = "submit" value="Upload File"/>
</form>

</body>
</html>

 

 

Link to comment
Share on other sites

i'm very sorry i have had little to no practice with uploading multiple files. this just goes woosh over my head ;). Hopefully someone else will have more knowledgable experience :D

 

you could try using print_r($_POST); on the page with the notices and check exactly what is being posted to the script.

 

eg:

 

<?php

// Debug Line
print_r($_POST); exit();

$things_to_replace="/\s/";
$replace_with='_';

$path_of_folder=preg_replace ($things_to_replace, $replace_with ,$_POST["create_this_folder"]);

Link to comment
Share on other sites

The "$_POST["create_this_folder"] - it is saying this POSTED variable does not exist." it does exist.

 

I think the fact that you are getting these error messages shows proves that it doesn't. You can say it exists all you want, but if it existed, then you wouldn't be getting these errors. The solution to your problem lies in figuring out why it isn't set, and how to set it.

Link to comment
Share on other sites

This is what I get as an output when I upload two files. 

 

var_dump($_FILES, $_POST);

 

Everything uploads fine.

 


array(1) { ["uploadedfile"]=>  array(5) { ["name"]=>  array(3) { [0]=>  string(12) "DSC_0500.JPG" [1]=>  string(0) "" [2]=>  string(12) "DSC_0624.JPG" } ["type"]=>  array(3) { [0]=>  string(10) "image/jpeg" [1]=>  string(0) "" [2]=>  string(10) "image/jpeg" } ["tmp_name"]=>  array(3) { [0]=>  string(80) "C:\Documents and Settings\Administrator\Local Settings\Temp\PHP\upload\php8A.tmp" [1]=>  string(0) "" [2]=>  string(80) "C:\Documents and Settings\Administrator\Local Settings\Temp\PHP\upload\php8C.tmp" } ["error"]=>  array(3) { [0]=>  int(0) [1]=>  int(4) [2]=>  int(0) } ["size"]=>  array(3) { [0]=>  int(2376919) [1]=>  int(0) [2]=>  int(3448569) } } } array(6) { ["preview_themes"]=>  string(3) "dsl" ["create_this_folder"]=>  string(0) "" ["MAX_FILE_SIZE"]=>  string( "10240000" ["experation0"]=>  string(9) "One Month" ["experation1"]=>  string(9) "One Month" ["experation2"]=>  string(9) "One Month" }

----------------------------------------------------

0 << the length of form field create_this_folder
lllloookkk
C:\Documents and Settings\Administrator\Local Settings\Temp\PHP\upload\php8A.tmp << temp name
DSC_0500.JPG << original name
image/jpeg << type
2376919 << size
<< temp name
<< original name
<< type
0 << size
C:\Documents and Settings\Administrator\Local Settings\Temp\PHP\upload\php8C.tmp << temp name
DSC_0624.JPG << original name
image/jpeg << type
3448569 << size

 

When I upload three files this is when it breaks.

 


array(0) { } array(0) { }

----------------------------------------------------


Notice: Undefined index: create_this_folder in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 12

Notice: Undefined index: create_this_folder in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 21

Notice: Undefined index: create_this_folder in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 22
0 << the length of form field create_this_folder
lllloookkk

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 27
<< temp name

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 28
<< original name

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 29
<< type

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 30
<< size

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 27
<< temp name

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 28
<< original name

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 29
<< type

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 30
<< size

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 27
<< temp name

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 28
<< original name

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 29
<< type

Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 30
<< size


 

Does anyone have ideas?

 

Link to comment
Share on other sites

Sometimes it works 1/30 + tries.

 

array(1) { ["uploadedfile"]=>  array(5) { ["name"]=>  array(3) { [0]=>  string(12) "DSC_0500.JPG" [1]=>  string(12) "DSC_0624.JPG" [2]=>  string(12) "DSC_0500.JPG" } ["type"]=>  array(3) { [0]=>  string(10) "image/jpeg" [1]=>  string(10) "image/jpeg" [2]=>  string(10) "image/jpeg" } ["tmp_name"]=>  array(3) { [0]=>  string(80) "C:\Documents and Settings\Administrator\Local Settings\Temp\PHP\upload\phpD3.tmp" [1]=>  string(80) "C:\Documents and Settings\Administrator\Local Settings\Temp\PHP\upload\phpD4.tmp" [2]=>  string(80) "C:\Documents and Settings\Administrator\Local Settings\Temp\PHP\upload\phpD5.tmp" } ["error"]=>  array(3) { [0]=>  int(0) [1]=>  int(0) [2]=>  int(0) } ["size"]=>  array(3) { [0]=>  int(2376919) [1]=>  int(3448569) [2]=>  int(2376919) } } } 

Link to comment
Share on other sites

Xeoncross, I installed php_xdebug and it is way better for debugging, thanks so much.  Look what I found as the error.

 

( ! ) Warning: POST Content-Length of 8604201 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

 

I guess I need to fix this in a config file.  Where and what do I edit to do this? 

 

Get php_xdebug from http://www.xdebug.org/docs/install

 

Thanks, Xeoncross

Link to comment
Share on other sites

[sOLVED SOLUTION]

 

Edit the PHP configuration file it should be "php.ini".

 

Find the following line.

 

; Maximum size of POST data that PHP will accept.

post_max_size = 8M

 

Chang it to an acceptable size that should match the max upload worst case scenario.

 

post_max_size = 20M

 

Yore done only 4 days later.  Also get XDEBUG http://www.xdebug.org/docs/install 

 

This will help you debig your work much better that what php has built in, check Appache logs also.

 

Thanks, All.

 

 

Link to comment
Share on other sites

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.