If 语句覆盖图像
我有一个表格设置。该表单有一个当前图像和一个添加新图像(代替该图像)的选项。
有问题的表单字段是:
<input type="hidden" name="image_url" value="<?php echo $row_select_propertyimages['image_url']; ?>" />
<input type="file" name="new_image_url" class="inputfile" />
我设置了一个 IF 语句,以检查是否设置了 new_image_url ,然后保留当前图像。否则,用 new_image_url 覆盖它。该代码如下。
if(!empty($_FILES['new_image_url'])) {
$image_url = $_POST['image_url'];
} else
$image_url = $_POST['new_image_url'];
但这始终输出原始文件。我怎样才能改变它以匹配?
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在检查“new_image_url”是否不为空,而您说您想检查它是否未设置。一个否定太多了。
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.
你的逻辑搞反了。当
new_image_url
为非空时,您将$image_url
设置为$_POST['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!
.