我在Linux中的Drobo5n上运行了一个Apache/PHP站点。
utilities.php在/合唱团/公司
hitCounter.txt在/合唱团/etc/tbc
在utilities.php中,我们有以下代码行:
$hits = file_get_contents('../etc/tbc/hitCounter.txt');它会产生此错误:
警告: /mnt/DroboFS/Shares/DroboApps/apache/www/Choir/inc/utilities.php (./etc/tbc/hitarib.txt):未能打开流:在第6行的file_get_contents中没有这样的文件或目录
这是我第一次使用PHP,我不知道为什么它找不到文件。我试过单引号和双引号,但都没有用。
我知道有人会要求获得完整的代码,下面是utilities.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;
}
?>发布于 2018-08-20 05:07:29
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/Choir2)检查file_exists
if (!file_exists($file)) {
//Throw error here
}3)检查:is_readable
if (!is_readable($File)) {
......
}https://stackoverflow.com/questions/51923899
复制相似问题