If 语句覆盖图像

发布于 2024-10-14 06:27:41 字数 556 浏览 5 评论 0原文

我有一个表格设置。该表单有一个当前图像和一个添加新图像(代替该图像)的选项。

有问题的表单字段是:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

新一帅帅 2024-10-21 06:27:41

您正在检查“new_image_url”是否不为空,而您说您想检查它是否未设置。一个否定太多了。

if(empty($_FILES['new_image_url'])) {
    $image_url = $_POST['image_url'];
} else 
    $image_url = $_POST['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.

if(empty($_FILES['new_image_url'])) {
    $image_url = $_POST['image_url'];
} else 
    $image_url = $_POST['new_image_url'];
甜嗑 2024-10-21 06:27:41

你的逻辑搞反了。当 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 !.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文