Reputation: 1686
I have a HTML form and am trying to parse it in PHP but none of the image inputs seem to be working as expected
My HTML is as follows:
<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>
Then in my PHP I just did:
if (isset($_POST['product_name'])) {
var_dump($_POST);
}
But the result I got shows none of the images being posted:
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)
I've treble checked everything, but can't see the cause.
Upvotes: 1
Views: 60
Reputation: 14862
File inputs are retrievable using the $_FILES
super global.
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
},
//...
}
Upvotes: 1