簡體   English   中英

PHP file_exists將不起作用

[英]PHP file_exists will not work

我一直在使用PHP中的file_exists函數時遇到問題,盡管該文件在那里,因為我可以刪除if語句,但它總是返回false,並且顯示得很好。

$filename = $_SERVER['DOCUMENT_ROOT']."/images/profilepictures/1.png";
if (file_exists($filename) == true)
{
    $output .= '<img src="'.$filename.'" alt="profile picture" width="200"/>';
}

$filename回顯為:

/home/content/k/e/r/kernelkev/html/images/profilepictures/1.png

我一直在使用Google搜索,大多數答案是使用DOCUMENT_ROOT,但它仍然對我不起作用。

任何人都可以對此有所了解,因為這現在真的很煩我。


這似乎可以解決...

$filename = "/images/profilepictures/1.png";
if (file_exists("..".$filename))
{
    $output .= '<img src="'.$filename.'" alt="profile picture" width="150"/>';
}

我不知道為什么,但是我們走了。

如果禁止該文件夾,file_exists不起作用。 嘗試將文件夾權限更改為777或755嗎?

sudo chmod 777 -R images/ 

如果您在php.ini中使用open_basedir,並且將file_exists用於open_basedir路徑之外的文件,則不會警告您日志,即使文件確實存在,file_exists也會返回false。 如果未由php用戶擁有文件權限而未啟用“其他”的文件權限讀取,則file_exists將很難找到您的文件。 我以為目錄名稱中有空格(/ users / andrew / Pictures / iPhoto Library / AlbumData.xml)遇到麻煩,但現實情況是圖片,iPhoto Library或AlbumData.xml沒有讀取權限。 一旦我解決了這個問題,file_exists就可以了。 當我們正確配置服務器時,這些將對我們正常工作,沒有問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM