I have this form:
<form action="image_upload.php" method="post" enctype="multipart/form-data">
Image 1: <input type="file" name="event_image" />
<input type="submit" />
</form>
and this php code (image_upload.php):
print_r($_FILES);
if ((($_FILES["event_image"]["type"] == "image/jpeg")
|| ($_FILES["event_image"]["type"] == "image/pjpeg"))
&& ($_FILES["event_image"]["size"] < 200000))
{
if ($_FILES["event_image"]["error"] > 0)
{
echo "Return Code: " . $_FILES["event_image"]["error"] . "<br />";
}
else
{
if (file_exists("/images/events/" . $_FILES["event_image"]["name"]))
{
echo $_FILES["event_image"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["event_image"]["tmp_name"],
"/images/events/" . $_FILES["event_image"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["event_image"]["name"];
}
}
}
else
{
echo "Invalid file";
}
I have no idea where this is going wrong as I've had the same code working before.
I am getting the following error though...
Array ( [event_image] => Array ( [name] => my_image.jpg [type] => image/jpeg [tmp_name] => /private/var/tmp/phpvIYmAZ [error] => 0 [size] => 48512 ) )
Warning: move_uploaded_file(../../../images/events/my_image.jpg): failed to open stream: Permission denied in /path/event_upload.php on line 25
Warning: move_uploaded_file(): Unable to move '/private/var/tmp/phpvIYmAZ' to '../../../images/events/my_image.jpg' in /path/event_upload.php on line 25 Stored in: upload/my_image.jpg
Notice: Undefined index: event_image in /path/event_upload.php on line 57
print_r($_FILES)at the top of it, please. Also, on theifyou should add the conditionisset($_FILES['event_image'])as the first condition to be evaluated. You should not evaluate anything else if that is false, or you'll get the undefined index errors.$_FILESpossibly because it failed to upload in the first place. Check if$_POST['event_image']is set and verify you didn't exceedmax_upload_sizeorpost_max_size