Link to home
Start Free TrialLog in
Avatar of dj__jebus
dj__jebus

asked on

PHP IIS fopen permission denied?

I am writing a small script that I need to write my data to a file on my web server.

    <?php
     $filename = $_POST['filename'];
     $data = $_POST['newdata'];
     $fh = fopen($filename, "w");
     fwrite($fh, $data);
     fclose($fh);
     echo "&nbsp &nbsp &nbsp &nbsp File has been successfully updated.<br>";
    ?>

Warning: fopen("about.html", "w") - Permission denied in C:\BlahDir\write.php on line 107

I am running IIS on winxp pro, and I have all the settings set that I could find to enable access for read/write and all that.  It only does this problem for opening the file for write, but only if the file exists.  If I manually delete the file first then it will create the file for me fine, but this is not an option for my situation.  I get the same error if I try to use unlink to delete the file first, so the problem is related somehow with writing to the existing files.  I have tried googleing this problem but nothing seems to have an answer that I can understand. (I'm very new to php and only know basics of my IIS).  I have read that this is possibly caused by the permissions of which php is running under in windows or something.  Please help, I am creating this so that I can update my website this way while I'm on a long vaction which I am leaving for very soon!

Thanks, Jebus
SOLUTION
Avatar of techtonik
techtonik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dj__jebus
dj__jebus

ASKER

How exactly do I check all those permissions?  It is my other pc that is running IIS with all this so I have full access to it.

Thanks, Jebus
Oh, and yes I can edit the files the second time around after php creates them.

Thanks, Jebus
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you so much, I can now update my files!  The only problem I now face is that when I have a " in my html files it replaces them with a bunch of \\\ charactors, but it works so I'm happy and I can probably figure this part out now, thanks so much!

Thanks, Jebus
First I must have to ask if you're using NTFS as your server's file system?
If so, then in file properties there should be tab called Security.
Sorry, answered for too long from hibernate - forgot to reload the page.
As for your files - use stripslashes() on your POST data. It is escaped, because you have enabled magic_quotes_gpc directive enabled in your php.ini

Hope this helps.