PHP的file_exists()对我不起作用? [英] PHP's file_exists() will not work for me?
问题描述
出于某种原因,下面的这个PHP代码无法正常工作,我无法弄清楚.
For some reason this PHP code below will not work, I can not figure it out.
这很奇怪, file_exists似乎看不到该图像确实存在,我已经检查以确保将正确的文件路径插入到file_exists函数中,并且它仍在起作用
It is very strange, file_exists does not seem to see that the image does exist, I have checked to make sure a good file path is being inserted into the file_exists function and it is still acting up
如果我将file_exists更改为!file_exists,它将返回存在的图像和不存在的图像
If I change file_exists to !file_exists it will return an images that exist and ones that do not exist
define('SITE_PATH2', 'http://localhost/');
$noimg = SITE_PATH2. 'images/userphoto/noimagesmall.jpg';
$thumb_name = 'http://localhost/images/userphoto/1/2/2/59874a886a0356abc1_thumb9.jpg';
if (file_exists($thumb_name)) {
$img_name = $thumb_name;
}else{
$img_name = $noimg;
}
echo $img_name;
推荐答案
file_exists()
需要使用硬盘驱动器上的文件路径,而不是URL.所以你应该有更多类似的东西:
file_exists()
needs to use a file path on the hard drive, not a URL. So you should have something more like:
$thumb_name = $_SERVER['DOCUMENT_ROOT'] . 'images/userphoto/1/2/2/59874a886a0356abc1_thumb9.jpg';
if(file_exists($thumb_name)) {
some_code
}
http://us2.php.net/file_exists
这篇关于PHP的file_exists()对我不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!