【发布时间】:2021-12-16 22:48:54
【问题描述】:
我对这段代码有疑问:
final public function logToSystem(string $message = '', string $anyName = '')
{
if(!file_exists(PATH_ROOT . '/logs')) {
mkdir(PATH_ROOT . '/logs', 777);
}
if(!is_writable(PATH_ROOT . '/logs/api_submissions_' . escapeshellarg($anyName) . '.log')) {
throw new Exception('ABORTING! Can not write to file: ' . PATH_ROOT . '/logs/api_submissions_' . escapeshellarg($anyName) . '.log');
}
file_put_contents(PATH_ROOT . '/logs/api_submissions_apiAction.log', $message, FILE_APPEND);
}
/logs/ 存在并且有 777。我已经将所有权设置为 www-data。
如果我想向我的 API 发送任何数据,我会收到以下错误:
[php7:error] [pid 544753] [client 12345:43019] PHP Fatal error: Uncaught Exception: ABORTING! Can not write to file: /var/www/html/logs/api_submissions_''.log in /var/www/html/admin/lib/controller/Controller_Admin_Articles.class.php:377\nStack trace:\n#0 /var/www/html/admin/lib/controller/Controller_Admin_Articles.class.php(492): Controller_Admin_Articles->logToSystem()\n#1 /var/www/html/core/lib/controller/Dispatcher.class.php(20): Controller_Admin_Articles->submitApiArticle()\n#2 /var/www/html/admin/index.php(7): Dispatcher::dispatch()\n#3 {main}\n thrown in /var/www/html/admin/lib/controller/Controller_Admin_Articles.class.php on line 377
有什么想法吗?
【问题讨论】:
-
/var/www/html/logs/api_submissions_''.log您的文件名未正确创建
标签: php permissions