Forum Moderators: coopster

Message Too Old, No Replies

fopen, fwrite, fclose

         

yllai

7:48 am on May 16, 2006 (gmt 0)

10+ Year Member



Hi,
I'm trying to open a file text.txt, then write some word to the file, then close it. Following is my script. However, I not successfully write data into test.txt. Any idea?

<?php
$file="test.txt";
$fp=fopen("$file","w");
chmod($index, 0777);
$content = "Hello, I am a File!";
fwrite($fp,$content);
chmod($index, 0644);
fclose($fp);

if (file_exists($file)) {
echo "<br>The file $file exists";
} else {
echo "<br>The file $file does not exist";
}
echo "</pre>";
?>

Any idea?

yllai

9:32 am on May 16, 2006 (gmt 0)

10+ Year Member



I understand that CHOMOD only can be done in non-windows server. Windows server not understand CHMOD command. But, I have hosted the windows server, anyway for me to CHMOD the file?

jatar_k

5:24 pm on May 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



did you get this to work yllai?

bgrobe

7:07 pm on May 17, 2006 (gmt 0)

10+ Year Member



If your Windows web server is configured correctly, you shouldn't have to do anything like a CHMOD. Windows has no support for anything like this without 3rd-party programs that cost $$$.

jezra

7:34 pm on May 17, 2006 (gmt 0)

10+ Year Member



who ever is running the script needs to have write access to the directory where the script exists. If the script is being run through a web interface, then the default website user, set by the webserver software, needs to have write access to the folder. On Windows running IIS 6, I believe the user is IUSER_COMPUTERNAME where COMPUTERNAME is the name of the computer.