【问题标题】:PHP File Upload - Field doesn't exist on action pagePHP 文件上传 - 操作页面上不存在字段
【发布时间】:2011-07-28 10:34:22
【问题描述】:

我有一个接受用户输入并要求他们上传文件的表单(图像,但这对于这个问题并不重要)。当用户按下提交时,文件的字段似乎没有传递给操作脚本。

表单定义如下:

<form name="AddProduct" id="AddProduct" method="post" enctype="multipart/form-data" action="dothing.php">
<tr>
<td >Item UPC</td>
<td><input name="upccode" type="text" id="upccode" size="40" value="" maxlength="255"></td>
</tr>
<tr>
<td>Item Description</td>
<td><input name="proddesc" type="text" id="proddesc" size="40" value="" maxlength="255"></td>
</tr>
<tr>
<td>Item Image</td>
<td><input type="file" name="file" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Add !" class="submit"></form></td>
</tr>

如果我在 dothing.php 上执行 print_r($_POST); 这就是我得到的结果

Array ( [upccode] => 159874288 [proddesc] => A fancy widget [submit] => Add ! )

如果我查看发布的请求,我会看到:

-----------------------------11192760525264\r\nContent-Disposition: form-data; name="upccode"\r\n\r\n159874288\r\n-----------------------------11192760525264\r\nContent-Disposition: form-data; name="proddesc"\r\n\r\nA fancy widget\r\n-----------------------------11192760525264\r\nContent-Disposition: form-data; name="file"; filename="gif.gif"\r\nContent-Type: image/gif\r\n\r\nGIF87a?à÷

我的 file 在 dothing.php 页面上的变量在哪里?它清楚地表明它正在通过。

【问题讨论】:

    标签: php html forms upload


    【解决方案1】:

    @Andy:file 不会出现在 $_POST 集合中,它会出现在 $_FILES 中。

    【讨论】:

    • 是的,所有文件都进入 $_FILES。 print_r($_FILES) 会给你它的结构。不要忘记将其复制到永久位置,因为它会上传到临时位置。
    猜你喜欢
    • 2014-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-23
    • 2015-04-11
    相关资源
    最近更新 更多