Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP folder permissions problem

I am trying to create a folder and then another folder within it using PHP.

If this is the directory structure I have

/home/site                           (owner : user1)

Now, I create the folder using

mkdir("/home/site/newdir",0777);     (user : apache)

The directory /home/site/newdir is created but the user of that directory is "apache"

Now, doing

mkdir("/home/site/newdir/anotherdir",0777);

doesnt create another directory inside newdir.

Please help. I think its a owner issue. I cannot change the owner using chmod() either. The owner remains the same.

What might be causing this ?

EDIT :

<?php
error_reporting(E_ALL);

mkdir("./m",0777);  // works
mkdir("./m/v",0777); // doesnt work

And no errors on the page.

var_dump(is_writeable("./m")) // returns bool(true)

EDIT : This has been fixed. For others who might be facing the same issue, It was because of PHP's safe mode being "on". Still dont know the reason behind what exactly does safe mode do that doesnt let you create nested directories.

But it works now. Thanks all for reading.

like image 827
YD8877 Avatar asked Feb 14 '26 06:02

YD8877


1 Answers

The mode on the directory created by mkdir() is affected by your current umask, which is why chmod() is not working for you.

Try:

$old_mask = umask(0);
mkdir("/home/site/newdir/anotherdir",0777);
umask($old_mask);
like image 83
avip Avatar answered Feb 16 '26 18:02

avip