skip to Main Content

My Website will contain thousands of subdirectories named ‘e’ which are to hold user created .json files specific to that directory’s submission form. I need this newly created directory to be chmod 0007. How can I do this?

This code below comes from a php file the global store function for local storage in folder ‘e’ but it only works right now if that folder is already there and already chmod 0007:

public function store(Document $document) {
    if (!isset($document->id)) { $document->id = $this->generateId(); }

        //This is my guess how to do it..
        $this->path      = $this->path . DIRECTORY_SEPARATOR
        if (!file_exists($this->path)) {
            mkdir($this->path);
            chmod($this->path, 0007);
        }
    //My guess does not work

    $path    = $this->getPathForDocument($document->id);
    $data    = $this->formatter->encode((array) $document);

    return file_put_contents($path, $data);
}

Note: I have searched other stack articles related to chmod via PHP, all are file related, not a directory, and/or none to date have been clear enough to help me. Please only link to something that specifically answers this exact question.

Note: This is not a question of which chmod is best. Thank you for your chmod #### concerns, I will consider those later. Please focus on an answer to the question, not one detail that bothers you, without answering.

2

Answers


  1. Chosen as BEST ANSWER

    Stumbled on this: PHP mkdir: PHP mkdir: Permission denied problem

    They suggested this: chown -R www-data:www-data /var/www/example.com/public_html/ chmod -R g+rw /var/www/example.com/public_html/

    It actually worked.

    Thanks :)


  2. foreach(['./users','./mp3','./pdf'] as $path){
        array_map(function ($val){
            return shell_exec ("chmod 0777 $val");
        }, glob("$path/*"));
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search