1

I've got a FORM Setup. The form has a current image and an option to add a new image (In place of that image)

The form fields in question are :

<input type="hidden" name="image_url" value="<?php echo $row_select_propertyimages['image_url']; ?>" />
<input type="file" name="new_image_url" class="inputfile" />

I've setup an IF Statement, to check that if new_image_url ISNT set, then to keep the current image. Otherwise, overwrite it with new_image_url. That code is as follows.

if(!empty($_FILES['new_image_url'])) {
    $image_url = $_POST['image_url'];
} else 
    $image_url = $_POST['new_image_url'];

But that is always outputting the ORIGINAL file. How can I change this to match?

Thanks in advance.

StuBlackett
  • 3,789
  • 15
  • 68
  • 113

2 Answers2

1

You're checking if 'new_image_url' is NOT EMPTY, while you say you want to check if it is NOT SET. One negation too many.

if(empty($_FILES['new_image_url'])) {
    $image_url = $_POST['image_url'];
} else 
    $image_url = $_POST['new_image_url'];
mrbellek
  • 2,300
  • 16
  • 20
0

Your logic is reversed. When new_image_url is not empty you are setting $image_url to $_POST['image_url']. It should be the other way round. Basically just remove the !.

Klaus Byskov Pedersen
  • 117,245
  • 29
  • 183
  • 222