[英]Why can't php find this file?
我有一個在Linux的Drobo5n上運行的Apache / PHP站點。
utilities.php位於/ Choir / inc
hitCounter.txt位於/ Choir / etc / tbc中
在utilities.php中,我們具有以下代碼行:
$hits = file_get_contents('../etc/tbc/hitCounter.txt');
產生此錯誤:
警告:file_get_contents(../ etc / tbc / hitCounter.txt):無法打開流:在第6行的/mnt/DroboFS/Shares/DroboApps/apache/www/Choir/inc/utilities.php中沒有此類文件或目錄
這是我第一次擺弄PHP,我不知道為什么找不到文件。 我嘗試過單引號和雙引號都無濟於事。
我知道有人會要求完整的代碼,所以這是Utility.php文件:
<?php
session_cache_limiter('private_no_expire');
session_start();
function getHitCount() {
$hits = file_get_contents('../etc/tbc/hitCounter.txt');
if (!isset ($_SESSION['beenHere'])) {
$hits = $hits + 1;
file_put_contents('../etc/tbc/hitCounter.txt', "$hits");
$_SESSION['beenHere'] = "Yes I have";
}
return $hits;
}
?>
1)應明確您的文件路徑。 在這種情況下很難說。 我們應該有我們的根應用程序文件夾。
如果我們遵循MVC模式,則將輕松獲得根應用程序文件夾。
例如https://github.com/daveh/php-mvc
我喜歡一些東西:
$file = APP_ROOT . '/etc/tbc/hitCounter.txt';
#APP_ROOT has the path /mnt/DroboFS/Shares/DroboApps/apache/www/Choir
2)檢查file_exists
if (!file_exists($file)) {
//Throw error here
}
3)檢查: is_readable
if (!is_readable($File)) {
......
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.