News:

LVCS.NET offers low cost domain registration services.

Main Menu

php File writing help

Started by nscelica, February 09, 2006, 08:00:17 PM

Previous topic - Next topic

nscelica

<?
$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?

admin

What error are you receiving?

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

Thank you,
FreePgs.com Admin

nscelica

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.

admin

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

nscelica

Well I tested it on the Freepgs server and it worked, but on the Plesk server it does not work.

admin

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

nscelica


sixthcrusifix

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.
Visite me website at http://www.sixthcrusifix.com