由于某种原因,下面的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;
Run Code Online (Sandbox Code Playgroud)
Ava*_*ava 83
file_exists()需要使用硬盘驱动器上的文件路径,而不是URL.所以你应该有更多的东西:
$thumb_name = $_SERVER['DOCUMENT_ROOT'] . 'images/userphoto/1/2/2/59874a886a0356abc1_thumb9.jpg';
if(file_exists($thumb_name)) {
some_code
}
Run Code Online (Sandbox Code Playgroud)
http://us2.php.net/file_exists
file_exists 仅适用于本地文件系统.
如果您使用localhost,请尝试此操作:
$thumb_name = 'images/userphoto/1/2/2/59874a886a0356abc1_thumb9.jpg';
if (file_exists($_SERVER['DOCUMENT_ROOT'].$thumb_name)) {
$img_name = SITE_PATH2.$thumb_name;
} else {
$img_name = $noimg;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
85306 次 |
| 最近记录: |