PHP 创建目录时抛错,Warning: mkdir(): Permission denied in xxx.php on line 45的解决办法

如下, PHP 创建目录时抛错,Warning:  mkdir(): Permission denied in aerchi_file_upload_parser.php on line 45

$cur_root_upload_path = $_SERVER['DOCUMENT_ROOT']."/aerchi/upload-2019/";
//创建目录失败
if (!file_exists($cur_root_upload_path ) && !mkdir($cur_root_upload_path , 0777, true)) {
    $data_result['msg'] = "ERROR_CREATE_DIR";
    // return;
} else if (!is_writeable($cur_root_upload_path )) {
    $data_result['msg'] = "ERROR_DIR_NOT_WRITEABLE";
    // return;
}

"Warning:  mkdir(): Permission denied in /usr/www/2019/aerchi/admin/aerchi_file_upload_parser.php on line 45
{"code":1,"msg":"guhua.jpg \u4e0a\u4f20\u5b8c\u6210.","time":"20190814 01:39:48","filepath":"\/aerchi\/upload-2019\/guhua.jpg"}"

解决方法: 

1. 赋予权限

chown -R nginx /usr/www/2019/aerchi/upload-2019/* && chmod 755 -R /usr/www/2019/aerchi/upload-2019/*

2. 查看路径,必须要以 域名相对路径 /usr/ 开始,如无,请添加.

$cur_root_upload_path = $_SERVER['DOCUMENT_ROOT']."/aerchi/upload-2019/";

 

 

你可能感兴趣的:(PHP 创建目录时抛错,Warning: mkdir(): Permission denied in xxx.php on line 45的解决办法)