Problem Writing To File

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello all.

Okay, this seems really stupid, but it's driving me up the wall.

I have a simple script I've written to log some information to a text
file. Everything seems to be okay, the code isn't throwing any errors,
but for some reason it isn't writing to file. If anyone has any ideas,
please let me know.

Here's the code I'm using:

//trigger_error("Just Testing to see if this is working",E_USER_NOTICE);
$strTimeStamp=date("F j, Y h:i:s A");
$strLogEntry=$strTimeStamp . ", " . $REQUEST_URI . ", " . $_SERVER
['HTTP_REFERER']. "\r\n";
//echo $strLogEntry;

echo "File Exists<br>";
echo "File Does Not Exist<br>";

echo "File Can Be Written to<br>";
echo "File Cannot Be Written to<br>";

$fileHandle=fopen($logfile, "a");

echo "File Opened for writing.<br>";
$written=fwrite($fileHandle, $strLogEntry);
echo "File written to successfully.<br>";
echo "File closed succesfully.<br>";

error_log("$logfile does not exist");

Randy Jackson

Re: Problem Writing To File

["Followup-To:" header set to comp.lang.php.]
Randy Jackson wrote:
Quoted text here. Click to load it

Turn on error reporting if you don't already have it.

Put these at the top of your scripts
    ini_set('display_errors', '1');

or change php.ini to have it on at all times.

Quoted text here. Click to load it
Not that it matters for the problem at hand,
but do you have "register globals" on?

Quoted text here. Click to load it
Shouldn't this be only "\n" and let the OS do the translation?
Again, it doesn't matter for your problem :-)

Quoted text here. Click to load it
text-mode translation; use "ab" for binary-mode.

Quoted text here. Click to load it

if ($written === false) echo "ERROR: Could not write to file.<br>";
else {
  echo "wrote $written bytes to file -- expected to write ";
  echo strlen($strLogEntry), ".<br>";

Quoted text here. Click to load it

Happy Bug Hunting :-)
USENET would be a better place if everybody read:    | to  mail  me:  simply |    | "reply" to this post, |      | *NO* MIME, plain text |                     | and *NO* attachments. |

Re: Problem Writing To File

On Fri, 29 Oct 2004 16:53:58 -0500 (more or less), Randy Jackson

Quoted text here. Click to load it

Your code worked for me!  I did have to add <? to the beginning and ?> to the
end, but that was it.  The contents of fce.log are "October 30, 2004 09:08:13
AM, , ".  Make sure you have create and write permissions in the logs
directory for the user id of your httpd daemon.

Site Timeline