我有这个表格:
<form action="image_upload.php" method="post" enctype="multipart/form-data">
Image 1: <input type="file" name="event_image" />
<input type="submit" />
</form>
和这个 php 代码(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";
}
我不知道这是哪里出了问题,因为我以前有相同的代码工作。
虽然我收到以下错误...
数组 ( [event_image] => 数组 ( [name] => my_image.jpg [type] => image/jpeg [tmp_name] => /private/var/tmp/phpvIYmAZ [error] => 0 [size] => 48512 ) )
警告:move_uploaded_file(../../../images/events/my_image.jpg):无法打开流:第 25 行 /path/event_upload.php 中的权限被拒绝
警告:move_uploaded_file(): Unable to move '/private/var/tmp/phpvIYmAZ' to '../../../images/events/my_image.jpg' in /path/event_upload.php on line 25 存储在:上传/my_image.jpg
注意:未定义索引:第 57 行 /path/event_upload.php 中的 event_image