Page 1 of 1

chmod a directory

Posted: Thu Jul 21, 2005 10:44 pm
by anjanesh
Hi

Im trying to chmod a directory to 777 using chmod("folder", 0777); but it gives the error

Code: Select all

Warning: chmod(): Operation not permitted in /xxx/xxx.php on line nn
Actually I want to write data to a file - if the file does not exist then create it. This file may be deleted manually many times. So I cannot chmod it to 777 manually.
I cant use chmod($ilename,0777) because the filename may not exist.

Any idea how to get this done ?
Thanks

Re: chmod a directory

Posted: Fri Jul 22, 2005 12:24 am
by nyy2000
anjanesh wrote:I cant use chmod($ilename,0777) because the filename may not exist.
How about checking wheter file exists before that using file_exists();?

I guess PHP or Apache running user (www or nobody in most cases) doesn't have permission to write on parent of "folder" directory. You would have to chmod chown the parent directory.

Re: chmod a directory

Posted: Fri Jul 22, 2005 12:55 am
by anjanesh
nyy2000 wrote: How about checking wheter file exists before that using file_exists();?
If it doesnt how would I create the file ? For that I would need to do chmod(0777) to that file which doesnt exist !

Posted: Fri Jul 22, 2005 1:41 am
by josh

Code: Select all

if (!file_exists("/example/file.dat")) {
 fopen('/example/file.dat', 'w');
}

Posted: Fri Jul 22, 2005 2:22 am
by nyy2000
jshpro2 wrote:

Code: Select all

if (!file_exists("/example/file.dat")) {
 fopen('/example/file.dat', 'w');
}
I think anjanesh is pointing out PHP doesn't have permission to write to that directory.
So, as I said, anjanesh needs to make the parent directory writable to Apache user.