2

I am making a Cpanel for a open cart and I have to Upload 3 images of a product like this

<label for="password" class="control-label"><b>Product image:</b></label>
   <div class="controls">
<input type="file" name="Upload" id="password" class="span9 required" required />
</div>
<label for="password" class="control-label"><b>Product image:</b></label>
   <div class="controls">
    <input type="file" name="Upload" id="password" class="span9 required" required />

</div>

<label for="password" class="control-label"><b>Product image:</b></label>
   <div class="controls">
    <input type="file" name="Upload" id="password" class="span9 required" required />
</div>

I have searched many file upload code but none can make my work easy. I am working in a Framework so I will send this data to database class: $this->mlogin->dbfunction($POST,$image1,$image2,$image3);

where my insert query will execute

here is the database code

public function product_upload($_POST,$path) {

    $this->insert_query="INSERT INTO `_product`(
                                             `_p_name`,
                                             `_p_cat`,
                                             `_p_brand`,
                                             `_p_price`,
                                             `_p_amount`,
                                             `_p_image`,
                                             `_p_dcrp`

                                             )
                                             VALUES(
                                             '" .$_POST['name'] . "',
                                                 '" .$_POST['cat'] . "',
                                                     '" .$_POST['brand'] . "',
                                                         '" .$_POST['price'] . "',
                                                             '" .$_POST['avail'] . "',
                                                             '" .$path . "',
                                                                 '" .$_POST['detail'] . "'
                                                                 )";

    return $this->select();
}
4

1 回答 1

0

除了未过滤输入的安全问题外,上传的文件在 $_POST 中找不到,但在 $_FILES 中有更复杂的布局。

只需执行 var_output($_FILES) 即可检查其内容并参考此处的文档:http: //php.net/manual/en/features.file-upload.php

要记住的步骤:

  • 设置表单编码类型:enctype="multipart/form-data"
  • 检查 $_FILES,而不是 $_POST

$_FILES 的布局:

$_FILES[$fieldname]['name']  // The original name of the file on the client machine.
$_FILES[$fieldname]['type']  // The mime type of the file. Unsafe! Dont rely on it!
$_FILES[$fieldname]['size'] // The size, in bytes, of the uploaded file.
$_FILES[$fieldname]['tmp_name'] // The temporary filename of the file on the server.
$_FILES[$fieldname]['error'] // The error code associated with this file upload.
于 2013-07-11T14:18:21.467 回答