Page 1 of 1
Can't write to file!!!
Posted: Thu Jun 05, 2003 6:35 am
by vangelis
The problem is simple... i just can't seem to be able to write anything to a file no matter what i've tried!!!
Here's my code:
Code: Select all
<?php
$browser_output = 'Success in writing to file!!';
$filename = 'http://localhost/testfile.txt';
$fp = fopen($filename, "w+b");
fwrite($fp, $browser_output);
fclose($fp);
?>
And one more thing, if i specify the $filename as "testfile.txt" instead of '
http://localhost/testfile.txt' i get the error message:
Warning: fopen("testfile.txt", "w+b") - Permission denied
Plz HELP!!! Thanx in advance
Posted: Thu Jun 05, 2003 7:11 am
by Wayne
what are the file permissions on that file? do you have the correct permissions to write to it?
Posted: Thu Jun 05, 2003 7:50 am
by vangelis
could u be a little more specific? I am new to this. I have set the permissions from within the IIS to read, write, execute scripts and just about anything there is. The file is definitely not readonly. Is there something else i need to do?
Posted: Thu Jun 05, 2003 8:01 am
by mikusan
go to that file, chmod it to 666 and it should work, technically you should be able to do it with 644 but when i changed webservers i had to make it 666 or it's won't budge.
Posted: Thu Jun 05, 2003 8:53 am
by vangelis
i tried chmod and i now get the error
Warning: chmod failed: Invalid argument
I tried it with both 666 and 644

Posted: Thu Jun 05, 2003 8:55 am
by []InTeR[]
Do you try chmod with php or with ftp?
Posted: Thu Jun 05, 2003 8:56 am
by vangelis
with php
Posted: Thu Jun 05, 2003 8:59 am
by vangelis
and when u say ftp what do u mean? the files are stored locally on my machine
Posted: Thu Jun 05, 2003 10:18 am
by Wayne
try fopen with the path to the file not going through a URL ie
Code: Select all
$filename = '/home/site/testfile.txt';
Re
Posted: Thu Jun 05, 2003 12:01 pm
by easyteck
You said that you're using IIS? is this running under Windows? Do you have a Linux machine running the php scripts?... The file you want to write in is in a linux system?... explain as detailed as you can so I could help you. I've done proccess with files using php including uploading files to a server, but need to know more details about the way you're working with!

Posted: Thu Jun 05, 2003 5:04 pm
by vangelis
Yes I am using WindowsXP and IIS as the server. There is no remote website involved, everything is coded locally on my machine. I have set all the permissions from within the IIS to be able to read and write to files and have made sure that the files are not readonly. And i still cannot write a simple line to an empty file!!
Posted: Thu Jun 05, 2003 5:09 pm
by vangelis
chears wayne, setting the file path with the correct manner solved the problem.
Same senario for me
Posted: Thu Aug 07, 2003 6:24 pm
by caboom
I'm on IIS, windows XP, (local machine) and I cant get it to write to a file either. I checked permissions, I tried all kinds of path description, and fopen just wont write to my file. Is there a setting in the php.ini file I should look at? Nothing was obvious in there. The last code I tried was this:
$header_file = 'c:\\Inetpub\\wwwroot\\projects\\form_sites\\header.txt';
if(!($fp = fopen($header_file, "wb"))) die ("Cannot write to header_file.");
fwrite($fp, $headerb);
fclose($fp);
note : ($headerb is a user input field)
I also looked at the log file for IIS and I get "200" at the end of the log. Don't know what that means.
dont matter what I make the path to "$header_file", nothing works.
I tried:
$header_file = 'c:\\Inetpub\\wwwroot\\projects\\form_sites\\header.txt';
$header_file = './header.txt'; (the file is in same directory as the script)
$header_file = 'header.txt';
$header_file = '
http://myurl/header.txt'; (no error when I do this, but the file stays empty)
one last thing... I copied vangelis code with Wayne's correction that supposed have worked for vangelis, and does not work for me.
any siggestions out there?
thanks
forget it I figured it out
Posted: Thu Aug 07, 2003 7:04 pm
by caboom
forget it I figured it out
thanks to all that where going to take time to help