dongyou9818 2013-05-04 12:14
浏览 74
已采纳

php编辑表单上的php上传文件,如果没有文件则阻止UPDATE

I have a form to Edit existing values in a MySQL table. One of the fields stores the filename of an image, (another stores the folder location of the image) The file has an upload field to upload another image and replace the image name in the original image name field.

This works fine if I choose a file, to replace the existing image. If I don't choose to replace the image, the field is UPDATE with the empty data.

Basically I am trying to only do the UPDATE sql query if there is an image chosen and uploaded.

I am using this code:

if(!empty($_FILES['file_slick']))
{
$slick = $_FILES['file_slick']['name'];
copy($_FILES['file_slick']['tmp_name'],'../images/product/'.$folder.'/'.$slick); 
$sql_slick = "UPDATE tbl_product SET prod_slick = '".$slick."' WHERE prod_id = '".$prodid."'";
mysql_query($sql_slick);
}

I have tried if(!empty($_POST['file_slick'])) but neither works. If a file is chosen and uploaded, it is moved to the correct folder and the image filename is updated into the field. If an image is not chosen, empty data is updated into the image filename field.

I have looked around the internet (and mostly here) and from what I can see, my check to prevent empty data should work.

Can anyone see anything wrong here?

  • 写回答

3条回答 默认 最新

  • doushao1087 2013-05-04 12:18
    关注

    try if(!empty($_FILES['file_slick']['name']))

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?