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 "        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
<?php
$filename = $_POST['filename'];
$data = $_POST['newdata'];
$fh = fopen($filename, "w");
fwrite($fh, $data);
fclose($fh);
echo "        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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh, and yes I can edit the files the second time around after php creates them.
Thanks, Jebus
Thanks, Jebus
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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.
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.
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.
ASKER
Thanks, Jebus