1

Planning a basic image up load to start, not done it before. Having a problem with the form not passing the picture to the PHP file. The errors i am recieving are;

Notice: Undefined index: file in C:\Users\PC\Documents\XAMPP\htdocs\php\addpic.php on line 2 Notice: Undefined index: file in C:\Users\PC\Documents\XAMPP\htdocs\php\addpic.php on line 8 Notice: Undefined index: file in C:\Users\PC\Documents\XAMPP\htdocs\php\addpic.php on line 9 Notice: Undefined index: file in C:\Users\PC\Documents\XAMPP\htdocs\php\addpic.php on line 10 Notice: Undefined index: file in C:\Users\PC\Documents\XAMPP\htdocs\php\addpic.php on line 11

HTML form

<div id="addpicdialog" title="Change Pic">
<p>Please Fill in out member information.</p>
<form name="changepic" method="POST" action="php/addpic.php?id=<?php echo $id ?>" >
<p>DISPLAY CURRENT PIC HERE</p>

<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input name="submit" type="submit" value="Submit" id="submit"  /> 
</form>
</div>

addpic.php

<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
?>
1
  • have you actually sent any data to the websit when you receive the error? and you should also add enctype="multipart/form-data" to your form. Commented Feb 13, 2014 at 17:49

2 Answers 2

2

Uploads requires multipart/form-data

Try this:

<form enctype="multipart/form-data" name="changepic" method="POST" action="php/addpic.php?id=<?php echo $id ?>" >

Tip:

Use isset(...): http://php.net/manual/en/function.isset.php

Sign up to request clarification or add additional context in comments.

Comments

0

Replace this:

 <form name="changepic" method="POST" action="php/addpic.php?id=<?php echo $id ?>" >

By:

 <form name="changepic" method="POST" action="php/addpic.php?id=<?php echo $id ?>" enctype="multipart/form-data" >

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.