我正在更新数据库中的数据,这里是我的问题:
以下是代码:
if (!empty($_FILES['fileToUpload'])) { $dest = 'images/Uploaded/'; if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'],$dest.$_FILES['fileToUpload']['name'])) $file = $dest.$_FILES['fileToUpload']['name']; }
而我想要如果$_FILES如果为空,当前文件存储在数据库中,我们只是保留它的价值,当我更新.在我的代码中会发生什么,当已经有现有的图像时,我不点击上传文件,已经存在的图像消失了.
请帮忙!
如果空文件发布,您需要从数据库中获取旧文件名,依赖ID
if(empty($_FILES)){ $qry = "select * from tablename where id = ? "; $q = $this->db->conn_id->prepare($qry); $q->bindValue(1,$id,PDO::PARAM_INT); $q->execute(); while($rows = $q->fetch(PDO::FETCH_ASSOC) ){ $filename = $rows['imagename']; } } else { $dest = 'images/Uploaded/'; if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'],$dest.$_FILES['fileToUpload']['name'])) $file = $dest.$_FILES['fileToUpload']['name']; }