警告:mkdir():php中的权限被拒绝


Warning: mkdir(): Permission denied in php

heey我正在尝试为每个用户创建一个文件夹的每个人都尝试登录我的php应用程序,我在这里得到了消息

我的php代码在这里

function createChatFolder($email) {
    if(!file_exists('../../conversation'.$email)){
        if(mkdir('../../conversation'.$email , 0777 ,true)){
            $myfile = fopen('/opt/lampp/htdocs/facebookMV/web/conversation/'.$email.'/status.xml', 'w+');
            if($myfile){
                $txt = '<?xml version="1.0"  encoding="utf-8"   ?>'.PHP_EOL.'<status>1</status>';
                fwrite($myfile, $txt);
                fclose($myfile);
            }else{
                echo 'there was an error while creating the status file';
            }
        }else{ 
            echo 'there was an error while creating thee '.$email.' folder ';
        }
    }
}

有人能告诉我问题是从哪里来的吗注意:我使用的是UBUNTU 14.04,这是对话文件夹的模式

drwxr-xr-x 7 daemon daemon 4096 نوف 25 00:32 conversation

首先需要更改
if(!file_exists('../../conversation'.$email)){ if(mkdir('../../conversation'.$email , 0777 ,true))

if(!file_exists('../../conversation/'.$email)){ if(mkdir('../../conversation/'.$email , 0777 ,true))

如果你想创建子文件夹。

然后您需要确保写入权限为运行php的用户启用,通常为www-data

如果不确定,可以使用以下命令:

ps aux | egrep '(apache|httpd)'

以确定哪个用户apache以.的身份运行

使用chmod为所有用户启用对文件夹的写入权限是危险的

所以您可以使用setfacl命令作为root,如下所示。

setfacl -m u:www-data:w /path/to/conversation