Welcome to WebmasterWorld Guest from 54.145.208.64

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

mkdir - Permission Denied :o(

   
1:43 pm on Jan 24, 2005 (gmt 0)

10+ Year Member



Hi again,

I'm having a spot of bother with the mkdir command, I get a permission denied error. I've tried running the command in the Linux shell and works okay.

I just can't understand why it won't create a directory.

Any ideas?

Code:

// current directory
echo getcwd() . "<br><br>";

chdir("$home_dir");

// current directory
echo getcwd() . "<br><br>";

$new=$home_dir.'/'.$new_cat.'/';

#echo "NEW DIR: $new<br><br>";

mkdir($new,0700);

This is the output...

mkdir(/home/oz/domain.com/Arts/Art_Noveau/): Permission denied

I've tried running this command, mkdir /home/oz/domain.com/Arts/Art_Noveau/ in linux shell, and it works fine.

Thanks

2:21 pm on Jan 24, 2005 (gmt 0)

10+ Year Member



The fact that you can do it while logged in might suggest you CHMOD the permissions in your directory ..?

the PHP manual for chmod.
[us3.php.net...]

There may also be a problem with your host using the $home_dir. In many cases this would take you back beyond the /web directory (which is how many hosts are set up) and of course they are not going to allow you to write to this directory.

It seems that you may just need a two liner...

$new = "../your_directory";
mkdir("$new", 0700);

The "../" signifies the "home" directory. This way you don't have to define it. So if you wanted to go further, youd just:

$new = "../$otherpath/$thispath";

There is no need for the . '/' . '/' in my opinion. I use double quotes.

Hope this helps :0)

--Zak

2:22 pm on Jan 24, 2005 (gmt 0)

10+ Year Member



Hi Woldie,

If 'you' can create a sub dir but your 'httpd-user' cannot, it may be a problem with the permission setting of the dir (Arts/) above that sub dir. Make sure, that both your shell user as well as your webserver can write and execute that Arts/ directory, fiddling with chown user:group on that above-dir and then doing a chmod on Arts/ accordingly.

Regards,
R.

2:37 pm on Jan 24, 2005 (gmt 0)

10+ Year Member



Thanks guy for the input.

I've finally cracked it!

I needed to do a chmod 777 in a directory where I will be creating all directories on the fly, if that makes any sense.

The script as it stood wouldn't let me do the chmod command, I think it was what Romeo said, but anyway I've got it to work.

So essentially create a directory called 'directory' chmod 777 that, and then let the script create the directories as required in that directory.

eg. /home/oz/domain.com/directory/Arts

Thanks again.

Woldie.

1:19 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



Changing directory perms to '777' is ... wrong. What you should do is chmod the directory to '775' and chgrp to 'www-data' (or 'apache' or 'nobody' or whatever your webserver runs as).
2:28 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



Thanks dcrombie,

I see what you mean by chmod 777, because now I can't even remove the directories I've created.

Thanks for the tip.

:o)