View Full Version : PHP permissions error.

05-06-2009, 08:45 PM
Currently I have a function that writes a PHP file to a directory given a random string.

My write function is as follows:

function write($where, $what){
$myFile = $where;
$fh = fopen($myFile, 'w');
fwrite($fh, $what);

The only problem with it is, the index.php file that I create in the directory needs to be able to run a password protect PHP script. I don't know how to write a file AND give it permissions. If anyone could help me do that, it would be awesome.

I need to give the file that the write() function creates permissions... <-- simple form.

05-06-2009, 08:59 PM
you need to chmod() your file.


05-07-2009, 02:44 AM
chmod it to 777

05-07-2009, 02:58 AM
The problem is, it creates a file every time a user submits the form. I know about CHmod, but I don't want to have to CHMod Every Single Form a user submits. That's a lot of work. Is there a way to automate Chmod using PHP? A script with full permissions dropping permissions to a lower file?

05-07-2009, 03:03 AM
If the file that is being created is in a variable, it's simple.

chmod("$myfile", 777);

05-07-2009, 03:49 AM
thanks so much for that. This problem has been resolved. And in an efficient manner :)
Thanks all who helped.

05-07-2009, 03:39 PM
I only suggest removing the double quotes in the provided PHP snippet since it speeds down the PHP parser.