Jump to content

Unidentified Index


aNubies
Go to solution Solved by haku,

Recommended Posts

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.

Link to comment
Share on other sites

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 by aNubies
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by aNubies
Link to comment
Share on other sites

  • Solution

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);
}
Link to comment
Share on other sites

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 by aNubies
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.