Have been pulling out my hair for the past 2 hours on this and am sure I am doing something really stupid.
<?php
mkdir("blah", 0777);
?>
This works through the command line and the folder gets created. But the same thing doesn't work when I try to run it through the browser. Any file permission issues?
[ErrorException] mkdir(): Permission denied. That means you do not have write permission on your project folder. Create a new folder, say 'myproject and run sudo chmod 777 myproject . Then move to 'myproject' folder and create project.
Methods: file_exists(): It is an inbuilt function that is used to check whether a file or directory exists or not. is_dir(): It is also used to check whether a file or directory exists or not. mkdir() : This function creates a directory.
The mkdir() creates a new directory with the specified pathname. The path and mode are sent as parameters to the mkdir() function and it returns TRUE on success or FALSE on failure. The mode parameter in mkdir() function is ignored on Windows platforms.
A directory in the path /usr/local/myfolder/ is missing, this is why you get the error. If you call mkdir -p , the missing path is created as well.
Could it possibly be that while running under the command line, the script inherits your permissions, but when running from the browser it doesn't?
In that case you would want to make your directory permissions 'write' for group.
Your web server (apache?) is running as it's own user, and doesn't have permission to write to the directory you're running mkdir in.
Give your web server's user permission to write to the directory by either A) making it Owner, B) adding it to the Group if the Group has write permission, or C) give Everyone write permission (not recommended for most setups).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With