aNubies Posted March 21, 2013 Share Posted March 21, 2013 Guys help here please, this driving me crazy. At first I'm working with this code its running fine, however for some unknown reason it keeps telling me this error now "Unidentified Index". $im = imagecreatefrompng($_FILES['fileUpload']['tmp_name']); imagepng($im, $_FILES['fileUpload']['name'], 9); the above code is what I'm working it is place in <head> tag, I'm just testing the code so thats the only code there. why is that Unidentified index then, please help need a quick response. Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/275964-unidentified-index/ Share on other sites More sharing options...
haku Posted March 21, 2013 Share Posted March 21, 2013 I'm pretty sure that there is more to the error than just "Unidentified index". Quote Link to comment https://forums.phpfreaks.com/topic/275964-unidentified-index/#findComment-1420052 Share on other sites More sharing options...
aNubies Posted March 21, 2013 Author Share Posted March 21, 2013 (edited) Thank you very much sir for the quick response, but I'm afraid thats the only error that I got. Now I got a new error here is the complete error. Undefined index: fileUploads in C:\inetpub\wwwroot\ImageReduce\index.php on line 8 Warning: imagecreatefrompng(): Filename cannot be empty in C:\inetpub\wwwroot\ImageReduce\index.php on line 8 Notice: Undefined index: fileUploads in C:\inetpub\wwwroot\ImageReduce\index.php on line 9 Warning: imagepng() expects parameter 1 to be resource, boolean given in C:\inetpub\wwwroot\ImageReduce\index.php on line 9 Edited March 21, 2013 by aNubies Quote Link to comment https://forums.phpfreaks.com/topic/275964-unidentified-index/#findComment-1420053 Share on other sites More sharing options...
haku Posted March 21, 2013 Share Posted March 21, 2013 I didn't say there were more errors, I said there was more to the error. You should always paste the full error, as we cannot guess what the error is. The error you are showing us says this: Undefined index: fileUploads However the code you showed us is not using the index fileUploads (it is using fileUpload). So the code you showed us is not the code that is causing the error. Quote Link to comment https://forums.phpfreaks.com/topic/275964-unidentified-index/#findComment-1420056 Share on other sites More sharing options...
aNubies Posted March 21, 2013 Author Share Posted March 21, 2013 (edited) Sorry I just changed the file input field name into 'fileUploads', but to make it more clearer let me paste the whole code. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> Reduce & Resize Images </title> <?php $im = imagecreatefrompng($_FILES['fileUploads']['tmp_name']); imagepng($im, $_FILES['fileUploads']['name'], 9); ?> </head> <body> <form action="" method="POST" enctype="multipart/form-data"> <label name="lblBrowser">Filename : </label> <input type="file" name="fileUploads" id="fileUploads" /><br /> <input type="submit" name="Upload" value="Upload" /> </form> </body> </html> Edited March 21, 2013 by aNubies Quote Link to comment https://forums.phpfreaks.com/topic/275964-unidentified-index/#findComment-1420057 Share on other sites More sharing options...
Solution haku Posted March 21, 2013 Solution Share Posted March 21, 2013 The error is telling yout that this doesn't exist: $_FILES['fileUploads'] $_FILES is only set after a form has been posted (with a file attached to it). So when you visit this page before submitting the form, you will see the error you are seeing. You can fix it like this: if(isset($_FILES, $_FILES['fileUploads']['tmp_name'])) { $im = imagecreatefrompng($_FILES['fileUploads']['tmp_name']); imagepng($im, $_FILES['fileUploads']['name'], 9); } Quote Link to comment https://forums.phpfreaks.com/topic/275964-unidentified-index/#findComment-1420059 Share on other sites More sharing options...
aNubies Posted March 21, 2013 Author Share Posted March 21, 2013 (edited) Great, now I just tried that and the error dissapear also. But now I got this error Warning: imagecreatefrompng(): Filename cannot be empty in C:\inetpub\wwwroot\ImageReduce\index.php on line 10 Warning: imagepng() expects parameter 1 to be resource, boolean given in C:\inetpub\wwwroot\ImageReduce\index.php on line 11 With some observation file input seems cannot upload exact or more than 2mb image. I've search Mr. Google about it and it gave me data-max-size and max-size attributes but it didn't work, do you know Sir Haku if theres a way around on how to manage the upload of file input? Thank you in advance. [Edit] can - cannot Edited March 21, 2013 by aNubies Quote Link to comment https://forums.phpfreaks.com/topic/275964-unidentified-index/#findComment-1420060 Share on other sites More sharing options...
haku Posted March 21, 2013 Share Posted March 21, 2013 tmp_name != name Quote Link to comment https://forums.phpfreaks.com/topic/275964-unidentified-index/#findComment-1420062 Share on other sites More sharing options...
aNubies Posted March 21, 2013 Author Share Posted March 21, 2013 If I directly put the path of the file in the imagecreatefrompng() it works but via file input it doesn't if its more than 2mb. Quote Link to comment https://forums.phpfreaks.com/topic/275964-unidentified-index/#findComment-1420063 Share on other sites More sharing options...
aNubies Posted March 21, 2013 Author Share Posted March 21, 2013 I got it, I just changed the upload_max_limit configuration of PHP, by default it is 2MB. Thank you very much for the responses . Quote Link to comment https://forums.phpfreaks.com/topic/275964-unidentified-index/#findComment-1420064 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.