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" />
开发者_Python百科
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.
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'];
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 !
.
精彩评论