11
This commit is contained in:
@@ -5,63 +5,6 @@
|
|||||||
|
|
||||||
use support\App;
|
use support\App;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 给文件设置写入权限
|
|
||||||
* @param string $filePath 文件路径
|
|
||||||
* @param int $permission 权限值,默认0664(较安全)
|
|
||||||
* @return bool 是否设置成功
|
|
||||||
*/
|
|
||||||
function setFileWritePermission($filePath, $permission = 0664) {
|
|
||||||
// 检查文件是否存在
|
|
||||||
if (!file_exists($filePath)) {
|
|
||||||
// 如果文件不存在,先创建文件
|
|
||||||
if (!touch($filePath)) {
|
|
||||||
error_log("无法创建文件: $filePath");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查当前是否已有写入权限
|
|
||||||
if (is_writable($filePath)) {
|
|
||||||
return true; // 已有写入权限,无需修改
|
|
||||||
}
|
|
||||||
|
|
||||||
// 尝试设置权限
|
|
||||||
if (chmod($filePath, $permission)) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
error_log("无法给文件设置权限:" . $filePath ."权限值:" .$permission);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用示例
|
|
||||||
$logFile = '/rh/webman_duanju/runtime/logs/webman-' . date('Y-m-d') . '.log';
|
|
||||||
|
|
||||||
// 确保目录存在
|
|
||||||
$logDir = dirname($logFile);
|
|
||||||
if (!is_dir($logDir)) {
|
|
||||||
mkdir($logDir, 0755, true); // 创建目录,权限755
|
|
||||||
}
|
|
||||||
|
|
||||||
// 给文件设置写入权限(使用0664权限,比0666更安全)
|
|
||||||
if (setFileWritePermission($logFile)) {
|
|
||||||
echo "文件已拥有写入权限: $logFile";
|
|
||||||
} else {
|
|
||||||
echo "无法设置文件写入权限,请检查服务器配置: $logFile";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
chdir(__DIR__);
|
chdir(__DIR__);
|
||||||
require_once __DIR__ . '/../vendor/autoload.php';
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user