if (!(file_exists(http://example.com/images/thumbnail_1286954822.jpg))) {
$filefound = '0';
}
为什么这个不起作用?
if (!(file_exists(http://example.com/images/thumbnail_1286954822.jpg))) {
$filefound = '0';
}
为什么这个不起作用?
if (!file_exists('http://example.com/images/thumbnail_1286954822.jpg')) {
$filefound = '0';
}
该函数要求传入一个字符串。
file_exists()
无法正确处理HTTP URL。
file_exists 函数检查指定路径下是否存在文件。
语法:
file_exists ( string $filename )
如果指定的文件或目录存在,则返回 TRUE
;否则返回 FALSE
。
$filename = BASE_DIR."images/a/test.jpg";
if (file_exists($filename)){
echo "File exist.";
}else{
echo "File does not exist.";
}
你可以使用另一种替代方法getimagesize(),如果指定路径中的文件/目录不可用,它将返回0(零)。
if (@getimagesize($filename)) {...}
PHP
的 get_headers() 函数。function check_file_exists_here($url){
$result=get_headers($url);
return stripos($result[0],"200 OK")?true:false; //check if $result[0] has 200 OK
}
if(check_file_exists_here("http://www.mywebsite.com/file.pdf"))
echo "This file exists";
else
echo "This file does not exist";
if(stripos(get_headers($file)[0],'200 OK'))
- iKev61根据您对Haim的评论,这是您自己服务器上的文件吗?如果是的话,您需要使用文件系统路径,而不是url(例如file_exists('/path/to/images/thumbnail.jpg')
)。
对我来说,file_exists()函数也无法正常工作。因此,我找到了这个替代解决方案。希望这个解决方案能帮助到其他人。
$path = 'http://localhost/admin/public/upload/video_thumbnail/thumbnail_1564385519_0.png';
if (@GetImageSize($path)) {
echo 'File exits';
} else {
echo "File doesn't exits";
}
if ($user->image) {
$filename = "images/" . $user->image;
if (file_exists($filename)) {
echo '<br />';
echo "File exist.";
} else {
echo '<br />';
echo "File does not exist.";
}
}