php 未过帐输入类型文件

62lalag4  于 2022-12-25  发布在  PHP
关注(0)|答案(1)|浏览(126)

我有一个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)

我已经仔细检查过了,但是找不到原因。

6qftjkof

6qftjkof1#

可以使用$_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
    },
    //...
}

相关问题