I am using a simple script to write form data to a text file. I am developing on a local server for an intranet using IIS 7. When I enter content in the form and click submit, I am redirected to the php processing file but all I get is a blank page and no new text file.
$content = $_POST[“content”];
$file = fopen(”announcement-7.txt”, “w”) or die(“can’t open file”);
fwrite($file, $content);
fclose($file);
?>
Am I running into a server permission issue? As far as I can tell I have permissions to write files to the server directory. I am new to PHP, so is my code wrong?
Any help would be appreciated. I am not interested in other methods of storing form data. I want to save to a .txt file.
No…I did not use Microsoft Word :mad:…I used Microsoft Publisher !
seriously though,
I grabbed some tutorials online and so the quotes probably came from there. Anyways, I reviewed my source code and cleaned up the quotes and added the line you suggested, but I am still getting the same response; a blank page.
I’ll keep looking into it. It’s got to be a simple that I am overlooking.
Yeah, both files are in the same folder. I’m wondering if I am overlooking a file/security permission. I tried building the form with ASP.NET using a VB script and received a server error message “File/page not found”.
It is acting as if the browser is restricted from opening the file.
I retried this function with ASP.NET, turned error reporting on (duh!), and received an accessed denied error. My guess is that I am running into the same problem with PHP.
Do you know of any good resources explaining how to grant write security permission for PHP applications. As I review the security, it appears that I should be able to run these scripts on the server, but obviously I am missing something.
I have to say that so far I have seen no evidence you have even got PHP running on this server.
If that file I suggested to you in post #6 is in your main doc root (wherever that is, depending on whether your are running iis or apache, whether you told IIS or Apache what your home directory is, and if you have the correct setting in PHP.ini AND you have it in your hosts file … ) then you should be accessing it as:
Ah, there may be a PHP issue. I ran the code you suggested and the only return I receive was the first paragraph element. The phpecho did not return the 2nd paragraph. Hmm…
Thanks for the advice. I was hoping there was some easy debugging feature that did not require me to dig into the server error logs (which I already did). I have confirmed that my problem is permissions. I do not have access to write to the directory, see errors below.
I’ll need to do some more research, because I thought I granted the right access to this folder. With it being on a local server, I do have full control of the file directory (create, delete, move, change files etc). My guess is that the server requires another permission setting so that the files can be created via the browser.
How can I check for proper file permissions? I am using IIS7?
–Here is the modified script I received the errors for—
<?php
ini_set(‘display_errors’,1);error_reporting(E_ALL);
$file = fopen(‘/data/intranet/Design-Development/slideshow/announcement7.txt’, ‘w’);
fwrite($file, ‘Test data input’);
fclose($file);
echo(‘Complete’);
?>
–Error Log Results–
Warning: fopen(/data/intranet/Design-Development/slideshow/announcement7.txt): failed to open stream: Permission denied in D:\Data\Intranet\Design-Development\Slideshow\announcement7-process.php on line 5 Warning: fwrite() expects parameter 1 to be resource, boolean given in D:\Data\Intranet\Design-Development\Slideshow\announcement7-process.php on line 6 Warning: fclose() expects parameter 1 to be resource, boolean given in D:\Data\Intranet\Design-Development\Slideshow\announcement7-process.php on line 7
Complete
Thanks for the input and the time. I figured it out. Everyhing works once I got the permissions in order.
However, I do need to learn more about best-practice when setting permissions. To make the script work I add IUSR to the directory permissions were the txt file was to be written. I have a feeling this is not the best or safest way to enable sercurity permission.