Page 1 of 1

PHP & Writing to Files

Posted: Sat Nov 05, 2005 5:21 pm
by ashonline
Hi

I have an issue on my Fedora Core 4 installation where PHP scripts can't write to text files.

As an example, I get the following in Apache error logs:
PHP Warning: fwrite(): supplied argument is not a valid stream resource...
PHP Warning: fclose(): supplied argument is not a valid stream resource...

Apache is running as user "apache", with the files in question having been chown'd to apache & chmod'd to 777.
SELinux is disabled.

"Safe mode" in php.ini is set to off, & it's configuration hasn't been altered since installation.

Running Apache 2.0.54-10.2 & PHP 5.0.4-10.4.

Can someone please help me with this one?

Thanks

Ashley

Posted: Sat Nov 05, 2005 5:31 pm
by John Cartwright
Post code

Posted: Sat Nov 05, 2005 5:55 pm
by ashonline
The code is from a tutorial (i'm a php newbie)...

Code: Select all

$fp = fopen("$DOCUMENT_ROOT/../php_files/orders.txt", 'ab');
fwrite($fp, $outputstring, strlen($outputstring));
fclose($fp);
I've had similar issues with writing to files when using phpBB & Subdreamer also.

Posted: Sat Nov 05, 2005 6:07 pm
by John Cartwright
change

Code: Select all

$DOCUMENT_ROOT
to

Code: Select all

$_SERVER['DOCUMENT_ROOT']

Posted: Sat Nov 05, 2005 6:40 pm
by ashonline
Sorry, I should have mentioned that at the top of the file I have:

Code: Select all

$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];

Posted: Mon Nov 07, 2005 10:41 am
by pickle
put $DOCUMENT_ROOT/../php_files/orders.txt in a variable, and echo that variable. It may be different than you expect.