Mkdir does not work in PHP

They have been pulling my hair for the last 2 hours on this, and I'm sure I'm doing something really stupid.

<?php mkdir("blah", 0777); ?> 

This works through the command line and a folder is created. But the same does not work when I try to run it through a browser. Any problems with file resolution?

+6
php mkdir
source share
3 answers

Could it be that when working on the command line, the script inherits your permissions, but when it starts from the browser, it is not?

In this case, you want your directory rights to be β€œrecorded” for the group.

+11
source share

Your web server (apache?) Works as its own user and does not have the right to write to the directory in which mkdir is running.

Grant the user of your web server the right to write to the directory either A) by making it Owner, B) adding it to the group if the Group has write permission, or C) grant all write rights (not recommended for most settings),

+3
source share

you can try using umask . When PHP is used as a server module, umask is restored after the completion of each request.

 $old = umask(0); mkdir($path,0777); umask($old); 
0
source share

All Articles