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
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 :)