简体   繁体   中英

Warning: mkdir(): Permission denied in php

heey everyone i'm trying to create a folder for every user try to sign into my php app and i get that message here

and my php code is here

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 ';
        }
    }
}

can any one tell me from where the problem is coming from NB : i'm using UBUNTU 14.04 and here is the mode of conversation folder

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

First you need to change
if(!file_exists('../../conversation'.$email)){ if(mkdir('../../conversation'.$email , 0777 ,true))

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

ie if you wish to create subfolders.

Then you need to make sure that write permissions are enabled for the user running the php, usually www-data .

If not sure, you could use the below command :

ps aux | egrep '(apache|httpd)'

to determine which user apache is running as.

Using chmod to enable write permissions for all the users to a folder is dangerous.

So you could use setfacl command as root like below.

setfacl -mu:www-data:w /path/to/conversation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM