0

好的程序员,我想在新年之前解决这个问题。我只想在照片存在时显示照片,否则使用默认照片。这是我始终正确返回“文件存在”的代码

<?php 
    $photolocation = '../wp-content/gallery/playerphotos/Joe Smith.jpg';
    if (!file_exists($photolocation))
    {
        echo "File exists";
    }
    else
    {
        echo "File does not exist";
    }
?>

当我更改photolocation为:

$photolocation = '../wp-content/gallery/playerphotos/XXX Smith.jpg';

我错误地得到“文件存在”。

我不明白为什么条件 !file_exists 总是返回一个正值。

4

1 回答 1

1

那应该是:

<?php 
    $photolocation = '../wp-content/gallery/playerphotos/XXX Smith.jpg';

    if (file_exists($photolocation))
    {
        echo "File exists";
    }
    else
    {
        echo "File does not exist";
    }
?>
于 2011-12-31T22:26:40.687 回答