1

为什么这不起作用?尝试使用 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"];
 }

不断收到未定义的索引错误但使用了“图像”?

谢谢

4

2 回答 2

3

您缺少enctype表单上的属性:

<form action="book_create.php" method="POST" enctype="multipart/form-data">
于 2014-04-04T22:01:35.753 回答
1

您需要enctype="multipart/form-data"在表单标签中包含

于 2014-04-04T22:04:52.050 回答