lindylex Posted April 10, 2008 Share Posted April 10, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/100562-solved-why-this-error-quotnotice-undefined-index-quot/ Share on other sites More sharing options...
uniflare Posted April 11, 2008 Share Posted April 11, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/100562-solved-why-this-error-quotnotice-undefined-index-quot/#findComment-514338 Share on other sites More sharing options...
lindylex Posted April 11, 2008 Author Share Posted April 11, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/100562-solved-why-this-error-quotnotice-undefined-index-quot/#findComment-514352 Share on other sites More sharing options...
uniflare Posted April 11, 2008 Share Posted April 11, 2008 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 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"]); Quote Link to comment https://forums.phpfreaks.com/topic/100562-solved-why-this-error-quotnotice-undefined-index-quot/#findComment-514357 Share on other sites More sharing options...
Xeoncross Posted April 11, 2008 Share Posted April 11, 2008 If you want to know WHAT is set then use this: <?php var_dump($_FILES, $_POST); ?> Quote Link to comment https://forums.phpfreaks.com/topic/100562-solved-why-this-error-quotnotice-undefined-index-quot/#findComment-514362 Share on other sites More sharing options...
haku Posted April 11, 2008 Share Posted April 11, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/100562-solved-why-this-error-quotnotice-undefined-index-quot/#findComment-514377 Share on other sites More sharing options...
uniflare Posted April 11, 2008 Share Posted April 11, 2008 var_dump adds string lengths etc - print_r is neater IMO Quote Link to comment https://forums.phpfreaks.com/topic/100562-solved-why-this-error-quotnotice-undefined-index-quot/#findComment-514395 Share on other sites More sharing options...
lindylex Posted April 11, 2008 Author Share Posted April 11, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/100562-solved-why-this-error-quotnotice-undefined-index-quot/#findComment-514933 Share on other sites More sharing options...
lindylex Posted April 11, 2008 Author Share Posted April 11, 2008 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) } } } Quote Link to comment https://forums.phpfreaks.com/topic/100562-solved-why-this-error-quotnotice-undefined-index-quot/#findComment-515027 Share on other sites More sharing options...
Xeoncross Posted April 11, 2008 Share Posted April 11, 2008 var_dump adds string lengths etc - print_r is neater IMO oops! your right - I got spoiled because I use Xdebug and that overwrites var_dump with an AWESOME new version. But with plain PHP var_dump isn't very good... Quote Link to comment https://forums.phpfreaks.com/topic/100562-solved-why-this-error-quotnotice-undefined-index-quot/#findComment-515159 Share on other sites More sharing options...
lindylex Posted April 11, 2008 Author Share Posted April 11, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/100562-solved-why-this-error-quotnotice-undefined-index-quot/#findComment-515267 Share on other sites More sharing options...
lindylex Posted April 11, 2008 Author Share Posted April 11, 2008 [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. Quote Link to comment https://forums.phpfreaks.com/topic/100562-solved-why-this-error-quotnotice-undefined-index-quot/#findComment-515271 Share on other sites More sharing options...
Xeoncross Posted April 13, 2008 Share Posted April 13, 2008 Yes, Xdebug is sweet Also get wincachegrind or xcachegrind so you can profile your scripts to track everything that was done and find bottle-necks functions that you can speed up. P.S. ugh...I hate problems that take 4 days... Quote Link to comment https://forums.phpfreaks.com/topic/100562-solved-why-this-error-quotnotice-undefined-index-quot/#findComment-516306 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.