PHP检查是否同时存在2个文件

时间:2022-10-28 21:45:41

I'm trying to check if two files exist at the same time in the same sentences and not work.. when I separate the sentences in two conditionals it work but together nothing happen, no error, no warning NOTHING... Please any suggestion?

我试图检查两个文件是否同时存在于同一个句子中并且不起作用..当我将两个条件中的句子分开时它起作用但是没有发生任何事情,没有错误,没有警告没有...请任何建议?

This is my simple code:

这是我的简单代码:

$folder_img_small = 'images/press/img_small/';
$folder_img_big   = 'images/press/img_big/';

$target = $folder_img_small;
$target = $target . basename( $_FILES['img_small_1']['name']);

$target2 = $folder_img_big;
$target2 = $target2 . basename( $_FILES['img_big_1']['name']);

if ( (file_exists($target)) && (file_exists($target2)) ) {
    echo "One of the files already exists with the same name.";
    $uploadOk = 0;
} 

1 个解决方案

#1


Why not try using an OR for this

为什么不尝试使用OR

if ( (file_exists($target)) || (file_exists($target2)) ) {
    echo "One of the files already exists with the same name.";
    $uploadOk = 0;
} 

Try and see if it works. It simply compares if it exists either in 1st target or in the 2nd. Once in exists in any then....

试试看它是否有效。它只是比较它是存在于第一目标还是存在于第二目标中。一旦存在于任何当时....

#1


Why not try using an OR for this

为什么不尝试使用OR

if ( (file_exists($target)) || (file_exists($target2)) ) {
    echo "One of the files already exists with the same name.";
    $uploadOk = 0;
} 

Try and see if it works. It simply compares if it exists either in 1st target or in the 2nd. Once in exists in any then....

试试看它是否有效。它只是比较它是存在于第一目标还是存在于第二目标中。一旦存在于任何当时....