【发布时间】:2012-01-31 05:30:30
【问题描述】:
好的程序员,我想在新年之前解决这个问题。我只想在照片存在时显示照片,否则使用默认照片。这是我始终正确返回“文件存在”的代码
<?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 总是返回一个正值。
【问题讨论】:
-
您意识到您是在要求您的
if评估该文件是否 存在?因此,您应该只在文件不存在时才获得file exists...除非我真的误解了file_exists()函数的某些内容。 -
@DavidThomas 是对的。从 if 条件中删除 NOT
! -
我同意@DavidThomas 和@xbonez。问题是,这也意味着你的路径都不起作用。
标签: php webpage displayobject