警告:mkdir():在PHP中权限被拒绝

时间:2015-11-25 18:06:37

标签: php shell

heey大家我正在尝试为每个用户创建一个文件夹,尝试登录我的php应用程序并收到该消息here

我的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

1 个答案:

答案 0 :(得分:3)

首先你需要改变
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命令。

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

相关问题