由于某种原因,下面的 PHP 代码将无法工作,我无法弄清楚。
很奇怪的是,
file_exists 似乎没有看到图像确实存在,我已经检查以确保将良好的文件路径插入到 file_exists 函数中并且它仍在运行
如果我将 file_exists 更改为 !file_exists 它将返回存在的图像和不存在的图像
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。所以你应该有更多类似的东西:
$thumb_name = $_SERVER['DOCUMENT_ROOT'] . 'images/userphoto/1/2/2/59874a886a0356abc1_thumb9.jpg';
if(file_exists($thumb_name)) {
some_code
}
https://www.php.net/file_exists https://www.php.net/file_exists
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)