gpt4 book ai didi

PHP 的 file_exists() 对我不起作用?

转载 作者:IT王子 更新时间:2023-10-29 01:06:30 31 4
gpt4 key购买 nike

由于某些原因,下面的 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
}

http://us2.php.net/file_exists

关于PHP 的 file_exists() 对我不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1287837/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com