好的程序员,我想在新年之前计算一下。我只想显示一张照片,如果它存在,否则使用默认照片。这里是我的代码总是正确返回“文件存在”file_exists()返回false,即使对于存在的路径也是如此
<?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';
我得到错误“文件存在”。
我无法弄清楚为什么condition!file_exists总是返回一个正值。
你会意识到,你问你的'if',以评估该文件是否确实不*** ***存在吗?因此,只有在文件不存在的情况下才应该使用'file exists',除非我真的误解了'file_exists()'函数。 – 2011-12-31 22:22:51
@DavidThomas是对的。如果条件为 – xbonez 2011-12-31 22:24:49
,请删除NOT'!'我同意@DavidThomas和@ xbonez。事情是,这也意味着你的两条路都不起作用。 – 2011-12-31 22:29:59