View Full Version : mkdir in PHP
Maurice
04-01-2001, 11:43 PM
Two-prong question.
1. Can we use PHP's mkdir() function?
2. What would be the path argument? (e.g.:
mkdir("/temp/new", 0700);
The permission number above also brings me to ask about what it should be set to in the parent directory. While I understand that 0777 leaves the directory wide open -- possibly an unwise thing to do, although I think I have go checks against it leading to chaos -- is it allowed as an argument?
I'd most appreciate any insights on mkdir()...
allen
04-02-2001, 12:47 AM
Path argument can be something like
"./newdirectory"
This makes the directory reside in the directory where the script is. Using a "../newdirectory" makes the script make the directory one level above the directory where it is located.
Using a "/home/something" will probably not work since we dont have permissions to directories outside our account user.
When you are creating a directory in a root directory for which you have full access, you can set permissions to anything you want.
allen
04-02-2001, 12:49 AM
0777 is not a good idea since it allows anyone to enter that directory, read,write, etc. You probably want to restrict it to 775
Maurice
04-02-2001, 01:53 AM
O.K....
I tried several permutations along the following theme, as you suggested.
mkdir("./newdir", 0775);
if (mkdir("./newdir", 0775)) {
echo("New dir created!");
} else {
echo("New dir NOT created...");
}
The manual at php.net refers to umask(), but that doesn't seem to be the solution. (?)
For both references to mkdir above, I get:
Warning: MkDir failed (Permission denied) in /home/username/public_html/dir.phtml on line 2
So what am not getting? Has it to do with the permission setting for public_html (although I did try changing that)?
By the way, _Professional PHP Programming_ from Wrox is just one of the many sources I turn to, and there it does provide the caveat "assuming we have the correct permissions." Unfortunately, it is short on examples.
I'll probably feel *really* stupid when confronted with the obviousness of the answer... :-(}
Cheers!
allen
04-02-2001, 02:44 AM
Hi , the solution is pretty simple :)
You dont have permissions to write in that directory!!
Do this to make it work:
Go to the directory where the script is in.
Make sure you set permissions for the directory where the script is in to 'write access' for the entity that is going to execute the script. In this case it is probably ALL.
So if test.php is in directory public_html, you need to set permissions for public_html to 757 if you are going to make the script run by running it in your browser.
Hope this helps! :)
allen
04-02-2001, 02:46 AM
Though if i were you, i wouldnt set public_html to 757 :). Maybe a sub directory in public_html.
Maurice
04-02-2001, 03:14 AM
I *thought* I had changed permissions correctly, but obviously I hadn't.
The tips on subdirectories and permissions are excellent. I'll actually sleep better tonight -- that's assuming I ever decide to go to bed!
Cheers! :D
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.