0

what i am trying to do is when an admin tries to create a new product to upload to the server an image of that and as it's name to be the product id.jpg. I have searched google with no result. The code seems to be right. Can someone help me please? I am using lamp as local test server.

<?php 
// Parse the form data and add inventory item to the system
if (isset($_POST['product_name'])) {

    $product_name = mysql_real_escape_string($_POST['product_name']);
    $price = mysql_real_escape_string($_POST['price']);
    $details = mysql_real_escape_string($_POST['details']); 
    $category = mysql_real_escape_string($_POST['category_choice']);
    $condition= mysql_real_escape_string($_POST['condition']);
    $supplier_choice= mysql_real_escape_string($_POST['supplier_choice']);
    $handling_time= mysql_real_escape_string($_POST['handling_time']);
    $weight= mysql_real_escape_string($_POST['weight']);
    $information_box= $_POST['information'];

    $pid = mysql_insert_id();
    // Place image in the folder 
    $newname = "$pid.jpg";
    move_uploaded_file( $_FILES['my_photo']['tmp_name'], "../inventory_images/$newname");


    header("location: products.php"); 
    exit();

}

?>

            <form action="add_product.php" enctype="multipart/form-data" name="my_Form" id="my_Form" method="post">


            <tr>
                <td>Φωτογραφία</td>
                <td>
                    <label>
                        <input type="file" name="my_photo" id="my_photo"/>
                    </label>
                </td>
            </tr>

            <tr>
                <td>&nbsp;</td>
                <td>
                    <label>
                        <input type="submit" name="button" id="button" value="Αποθήκευση" />
                    </label>
                </td>
            </tr>

        </table>

        </form>
4

2 回答 2

0

我认为,如果您精简代码以仅包含与问题相关的部分,那么您将获得更好的答案。完成此操作后,您可能会看到自己问题的答案。

例如,文件是否上传成功?如果不是,那么 mysql_xxx 代码和您的大部分表单与您的问题无关。

于 2012-05-09T05:16:30.690 回答
0

如您所说,您正在使用lamp,请检查您上传文件的目录的权限。此外,还要检查您在目标路径中提到的所有文件夹的权限。

上传文件的目录和路径中的所有目录都必须有写权限。

如果 move_uploaded_file 不起作用,请尝试复制功能。还要检查您上传的路径是否正确。

于 2012-05-09T05:23:39.143 回答