【问题标题】:Undefined index: image未定义索引:图像
【发布时间】:2014-05-17 09:57:15
【问题描述】:

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

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

谢谢

【问题讨论】:

    标签: php file-upload undefined-index


    【解决方案1】:

    您的表单中缺少enctype 属性:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2016-04-14
        • 2014-06-25
        • 2016-04-16
        • 1970-01-01
        • 1970-01-01
        • 2015-11-25
        • 2012-10-18
        • 2012-03-08
        相关资源
        最近更新 更多