输入类型文件未发布

时间:2018-03-06 10:53:53

标签: php html post file-upload

我有一个HTML表单,我试图在PHP中解析它,但没有任何图像输入似乎按预期工作

我的HTML如下:

<form action="admin_catalog.php" name="new_product_form" id="new_product_form" method="post" enctype="multipart/form-data">
<table class="table">
<tr><td>Product Name:</td><td><input type="text" id="product_name" name="product_name"></td></tr>
<tr><td>Sort Order:</td><td><input type="number" id="product_sort" name="product_sort" value="1"></td></tr>
<tr><td>Category:</td><td><select name="product_category" id="product_category"><?php echo $category_options; ?></select></td></tr>
<tr><td>Product Attributes:</td><td><select name="product_attribute" id="product_attribute"><?php echo $attribute_options; ?></select></td></tr>
<tr><td colspan="2"><hr></td></tr>
<tr><td>Product Images:</td>
<td>
    <input type="file" id="product_image_1" name="product_image_1">
    <input type="file" id="product_image_2" name="product_image_2">
    <input type="file" id="product_image_3" name="product_image_3">
    <input type="file" id="product_image_4" name="product_image_4">
    <input type="file" id="product_image_5" name="product_image_5">
</td>
</tr>
<tr><td colspan="2"><hr></td></tr>
<tr><td>Product Description:</td><td><textarea id="product_description" name="product_description" style="width:170px;height:100px;"></textarea></td></tr>
<tr><td colspan="2"><hr></td></tr>
<tr><td>Supplier:</td><td><input type="text" id="product_supplier" name="product_supplier"></td></tr>
<tr><td>Suppliers Model No:</td><td><input type="text" id="product_model_no" name="product_model_no"></td></tr>
<tr><td>Suppliers Cost:</td><td><input type="text" id="product_cost" name="product_cost"></td></tr>
</table>
<input type="submit" id="product_submit" name="product_submit" value="Add Product">
</form>

然后在我的PHP中我刚刚做了:

if (isset($_POST['product_name'])) {
    var_dump($_POST);
}

但我得到的结果显示没有发布的图片:

array (size=9)
  'product_name' => string 'tgjss' (length=5)
  'product_sort' => string '1' (length=1)
  'product_category' => string '1' (length=1)
  'product_attribute' => string '2' (length=1)
  'product_description' => string 'dfhksfhg' (length=8)
  'product_supplier' => string 'ksgfhk' (length=6)
  'product_model_no' => string 'sgfk' (length=4)
  'product_cost' => string 'sfgk' (length=4)
  'product_submit' => string 'Add Product' (length=11)

我高音检查过所有内容,要么我错过了一些愚蠢的事情,要么我已经忘记了如何编码。任何对此的帮助都将非常感谢

1 个答案:

答案 0 :(得分:1)

可以使用$_FILES超级全局检索文件输入。

var_dump($_FILES);

array(5) { 
    ["product_image_1"]=> array(5) { 
        ["name"]=> string(12) "somefile.ext" //stores the original filename from the client
        ["type"]=> string(0) "" //stores the file’s MIME-type
        ["tmp_name"]=> string(0) "" //stores the name of the designated temporary file
        ["error"]=> int(0) //stores any error code resulting from the transfer
        ["size"]=> int(0) //file size in bytes
    },
    //...
}