加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 21:48:56 所属栏目:PHP教程 来源:网络整理
导读:我有以下表格: 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
我有以下表格:

<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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读