Page 1 of 2
Create A Directory
Posted: Tue Feb 28, 2006 2:07 pm
by icesolid
Is it possible to have PHP create a directory, and if so is it possible to set the permissions of this directory to read and write?
Posted: Tue Feb 28, 2006 2:13 pm
by neophyte
Code: Select all
chmod('0777', 'somedir');
mkdir('somedir');
Posted: Tue Feb 28, 2006 2:17 pm
by sman317
Two steps:
1. mkdir("/path/to/my/dir"); //Makes the directory
2. chmod("/path/to/my/dir", 0644); //Changes the permissions to Read and write for owner, read for everybody else
Errors
Posted: Tue Feb 28, 2006 2:33 pm
by icesolid
I get these two errors when using the code above:
Warning: mkdir(somedir): Permission denied in /home/capous/public_html/test.php on line 2
Warning: chmod(): No such file or directory in /home/capous/public_html/test.php on line 3
Also I want this new folder to be created in a existing directory named 'photos', this directory is located in my www main directory.
Posted: Tue Feb 28, 2006 2:35 pm
by chrys
umm... I believe it's part of the mkdir function
mkdir( "dir", 0777);
Posted: Tue Feb 28, 2006 2:35 pm
by chrys
php.net, the first resource before phpdevnetwork...
http://us3.php.net/mkdir
Posted: Tue Feb 28, 2006 2:51 pm
by icesolid
I figured it out.
The chmod code that was posted was in the wrong order, the directory location goes first, then permissions.
And yes, I did use the manual, thank you!
Posted: Tue Feb 28, 2006 3:07 pm
by icesolid
The only thing that seems weird is that if I use the code below it sets the directory at 357, which doesent give group permission to view the directory.
Code: Select all
mkdir("/home/capous/public_html/photos/" . $control_number . "", "0700");
chmod("/home/capous/public_html/photos/" . $control_number . "", "0750");
I want the directory permission to be 757, however if I use 0757 is chmod it doesent work.
Posted: Tue Feb 28, 2006 3:10 pm
by neophyte
Try 0755. Sorry about the reversal!

Posted: Tue Feb 28, 2006 3:18 pm
by icesolid
No its not working.
Here is my code:
Code: Select all
include("connect.php");
$result = mysql_query("SELECT * FROM cases ORDER BY control_number DESC");
$row = mysql_fetch_array($result);
$control_number = $row["control_number"] + "1";
mkdir("/home/capous/public_html/photos/" . $control_number . "", "0700");
chmod("/home/capous/public_html/photos/" . $control_number . "", "0755");
It creates the directory, but it sets it two 363 now?
Posted: Tue Feb 28, 2006 3:20 pm
by feyd
you may be hitting a umask restriction that disallows creations of that permission.
Posted: Tue Feb 28, 2006 3:22 pm
by neophyte
Someone tell me if I'm kracked, but if you are making a directory in a directory that isn't 0777 you won't get anywhere.
Posted: Tue Feb 28, 2006 3:28 pm
by icesolid
The photos dir is set at 777.
I want the directories created in photos to be 757 or 777, neither is working, and I don't even see 757 or 777 on php.net.
Posted: Tue Feb 28, 2006 3:31 pm
by neophyte
Like feyd said, mkdir() may be a banned function on your server. check with your host.
Posted: Tue Feb 28, 2006 3:33 pm
by feyd
I never said
mkdir() may be banned. I was talking about
umask().