file_exists()返回false,即使对于存在的路径也是如此

时间:2011-12-31 22:20:43

标签: php webpage displayobject

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

<?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总是返回正值。

1 个答案:

答案 0 :(得分:1)

应该是:

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

    if (file_exists($photolocation))
    {
        echo "File exists";
    }
    else
    {
        echo "File does not exist";
    }
?>