FreePgs.com Forum

FreePgs Related => Support Requests => Topic started by: nscelica on February 09, 2006, 08:00:17 PM

Title: php File writing help
Post by: nscelica on February 09, 2006, 08:00:17 PM
<?
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");

$stringData = "Bobby Bopper\n";
fwrite($fh, $stringData);

$stringData = "Tracy Tanner\n";
fwrite($fh, $stringData);
fclose($fh);
?>


Thats just an example of a file writing script i have on my page. I have already created that file "testFile.txt" and put it in the same directory as the php script but I cannot seem to get it to work.

Anyone have any ideas?
Title: Re: php File writing help
Post by: admin on February 09, 2006, 08:30:14 PM
What error are you receiving?

You may try to specify the complete path to the file.

Thank you,
FreePgs.com Admin
Title: Re: php File writing help
Post by: nscelica on February 09, 2006, 11:10:46 PM
I have tried all kinds of scripts. I am not getting any errors for the server, just blank pages and the files aren't in the path the file is in. I tried to set the path but I am still having no luck.

Do you think you could show me an example of a working file writing script for this server?

Basically what i'm trying to get accomplished is having info taking off the server and stored in txt files for each of the moderators of my site everytime they log in. I could do this with the database, but I figured its easier and more efficient to put the information in txt files.
Title: Re: php File writing help
Post by: admin on February 10, 2006, 12:04:32 AM
Be sure you have not disabled or changed the error logging.  Usually a blank page means errors were present but no logging is enabled.

Please try to specify the full file path such as /fpgs/fpgshttpd/<username>/filename

Also, be sure the file has the proper permissions.  (The default 644 may not work, you may need to change the permissions to 666 on this file)

Thank you,
FreePgs.com Admin
Title: Re: php File writing help
Post by: nscelica on February 10, 2006, 12:28:44 AM
Well I tested it on the Freepgs server and it worked, but on the Plesk server it does not work.
Title: Re: php File writing help
Post by: admin on February 10, 2006, 02:06:04 AM
Check the permissions of your files.

On the FreePgs server, PHP is running under the same username as the files.

On the Plesk server, this is not the case.  The files you wish to write must be chmod'd to 666 or better.
[If the script creates files, the directory may need to be set to 777]

Thank you,
FreePgs.com Admin
Title: Re: php File writing help
Post by: nscelica on February 10, 2006, 03:07:44 AM
THANK YOU, that worked.
Title: Re: php File writing help
Post by: sixthcrusifix on February 10, 2006, 07:01:00 PM
Quote from: nscelica on February 09, 2006, 08:00:17 PM
<?
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");

$stringData = "Bobby Bopper\n";
fwrite($fh, $stringData);

$stringData = "Tracy Tanner\n";
fwrite($fh, $stringData);
fclose($fh);
?>


Thats just an example of a file writing script i have on my page. I have already created that file "testFile.txt" and put it in the same directory as the php script but I cannot seem to get it to work.

Anyone have any ideas?

That's very strange because I just copied teh code you gave me and it worked just fine, I made a .txt file with "Bobby Bopper
Tracy Tanner" printed in it.