How do I append to a file in windows system?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
E_Fox
Forum Newbie
Posts: 9
Joined: Sun Jan 12, 2003 11:33 pm

How do I append to a file in windows system?

Post by E_Fox »

This is not working on windows:

Code: Select all

$file1 = fopen("list.txt", "ab");
or

Code: Select all

$file1 = fopen("list.txt", "a");

fanx in advance
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Do you get any error messages?

Mac
E_Fox
Forum Newbie
Posts: 9
Joined: Sun Jan 12, 2003 11:33 pm

Post by E_Fox »

No error messages, only it doesn't append to the file. It's windows NT server.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

works well on w2k. What does this script output?

Code: Select all

<?php
ini_set('display_errors', TRUE);	// ; Print out errors (as a part of the output).
ini_set('error_reporting', E_ALL);	//  ; E_ALL  - All errors and warnings 
$file1 = fopen('list.txt', 'ab');
if ($file1)
{
	fputs($file1, date('H:i:s')."\n");
	echo 'done.';
}
else
	echo 'failed.';
?>
E_Fox
Forum Newbie
Posts: 9
Joined: Sun Jan 12, 2003 11:33 pm

Post by E_Fox »

it says:
Warning: fopen("list.txt", "ab") - Permission denied in d:\inetpub\webs\efox\writ.php on line 4
failed.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

then this is the error ;)
filesystem permissions do not allow your script to write that file.
The script is not running under your account's permission settings but under the webserver's (or what ever it switched to before executing the script)
E_Fox
Forum Newbie
Posts: 9
Joined: Sun Jan 12, 2003 11:33 pm

Post by E_Fox »

how do I set permission to write on windows? I can't chmod on windows :(
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

e.g. by right-clicking on a file in the windows-explorer->properties->permissions(?). There you can set permissions on a user and/or group base.
You can as well change directory settings (might be nessecary).
The windows-help-system should provide more detail (e.g. inheritage of permission settings)
E_Fox
Forum Newbie
Posts: 9
Joined: Sun Jan 12, 2003 11:33 pm

Post by E_Fox »

I connect through an ftp client and thanks for the help.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Post Reply