CHMODing In PHP

Posted by gamehawk on Feb. 25, 2006, 8:09 a.m.

How do I use the chmod command in PHP. I've tried everything, so here's what I do.

1. Reset the file I want to try to chmod to nothing.

2. Upload PHP File (same dir as file trying to chmod)

3. Close FTP client

4. Run the script

5. Go back into the FTP client

6. The chmod of the previously clear file is Owner Read and Write: I tried chmoding with 0775 or 755 I tried:

chmod("file.txt", 0755);

chmod("file.txt", 755);

I've also tried using other common numbers used in FTP. None seem to work, everytime no matter what number it sets it to owner read and write and nothing else. What do I do? My error message is:

Warning: chmod(): Operation not permitted in /xxx/xxxx/xxxx/xxxx/test.php on line 7, line 7 is the chmod command, and test.php is the script trying to execute the chmod command.

Comments

flashback 18 years, 10 months ago

Well duh - You need to set the chmod to allow access by php (777)

gamehawk 18 years, 10 months ago

I tried 777 already, same thing should I try 0777

firestormx 18 years, 10 months ago

I had that problem too.

Turns out, the numbers have to be a string. As in chmod('file', '0777');

(notice the quotations around the 0777)

Took me so long to figure that out.

Anyway, if you want a mysql account, e-mail me the username and password you want to use, and I'll set you up with an account and database.

gamehawk 18 years, 10 months ago

Okay, thanks FSX. This will be better. Emailed it to your hotmail account.