Hey guys, same script as my last post "File Upload Problem". Now on my page I have it list all the information including the current photo that was uploaded using the original script. Problem is, now I need it to check and see if the user decides to change the photo it will upload the new image and update the path in the database. This part works great and I have it solid. The issue is that if the user doesn't change the picture and instead submits the form with a blank upload input, I get the error in my checking of "cannot upload file".
Here's the modified code:
if($_POST['file'] != $listingPhoto){
$target_path = "../propimages/listingPhotos/";
$tmp_name = $_FILES['file']['tmp_name'];
$name = $_FILES['file']['name'];
if(!move_uploaded_file($tmp_name, "$target_path$name")){
if(!is_writable($target_path)){
echo "path not writable<br />";
}
echo "Could not upload the file<br />";
echo "$target_path$name<br />";
echo $target_path."<br />";
exit();
}else{
$listingPhoto = "$target_path$name";
}
$listingPhoto = $listingPhoto;
}
In this case $listingPhoto is passed as the path of the current image in a hidden field to the script. In essence what I'm trying to do is say that if the user doesn't provide a new picture to upload, then take the file passed from the hidden element and re-insert it into the db. I hope this makes sense. Like I said, the new photo update works great, I'm just stumped on how to tell it to use the hidden data (current photo path) if nothing is submitted for upload.
Much TIA!