未定义的索引:图像

时间:2014-04-04 22:00:08

标签: php file-upload undefined-index

为什么这不起作用?尝试使用PHP上传文件。有问题的文件是只需要存储文件路径的图像。尝试此代码但不起作用。有什么帮助吗?

<html>
<body>
<form action="book_create.php" method="POST">
title: <input type="text" name="title"/><br>
authors: <input type="text" name="authors"/><br>
description: <textarea type="text" name="description"></textarea><br>
price: <input type="text" name="price"/><br>
image: <input type="file" name="image"/><br>
content: <input type="file" name="content"/><br>
<input type="submit" value="book_create"/>
</form>
</body>
</html>

PHP:

if ($_FILES["image"]["error"] > 0)
{
echo "Error: " . $_FILES["image"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["image"]["name"] . "<br>";
echo "Type: " . $_FILES["image"]["type"] . "<br>";
echo "Size: " . ($_FILES["image"]["size"] / 1024) . " kB<br>";
echo "Stored in: " . $_FILES["image"]["tmp_name"];
 }

继续使用未定义的索引错误但是使用了“image”?

由于

2 个答案:

答案 0 :(得分:3)

您错过了表单上的enctype属性:

<form action="book_create.php" method="POST" enctype="multipart/form-data">

答案 1 :(得分:1)

您需要在表单标记

中加入enctype="multipart/form-data"