微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 上传文件表单 – 无法识别$_FILES变量

我有以下表格:

<form method="post" action="index.PHP">
    product name:
    <input type="text" name="product_name" value="<?PHP echo $product_name;?>"/>
    <br /> <br />
    product details
    <textarea rows = "6" cols = "30" name="product_details" > <?PHP echo $product_details;?></textarea>
    <br /> <br />
    product price
    <input type="text" name = "product_price" value="<?PHP echo $product_price;?>"/>
    <br /> <br />
    CN:
    <input type="text" name = "product_cn" value="<?PHP echo $product_cn;?>"/>
    <br /> <br />
    image
    <input type="file" name="fileField" />
    <br /> <br />

    <input type="submit" name="submit" value="register product" />
</form>

我的问题是,每当我尝试使用此代码处理图像时:

move_uploaded_file($_FILES['fileField']['tmp_name'], "../product_images/$newname");

我收到以下错误

Notice: Undefined index: fileField

这是为什么?

提前致谢!

解决方法:

您必须在表单中添加enctype =’multipart / form-data’
Quote from this topic about this

When you make a POST request, you have to encode the data that forms the body of the request in some way.

HTML forms provide two methods of encoding. The default is
application/x-www-form-urlencoded, which is more or less the same as a
query string on the end of the URL. The other, multipart/form-data, is
a more complicated encoding but one which allows entire files to be
included in the data.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐