Problem Writing To File

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Problem Writing To File

    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;
    $logfile='../logs/fce.log';

    $logExists=file_exists($logfile);
    if($logExists){
    echo "File Exists<br>";
    }
    else{
    echo "File Does Not Exist<br>";
    }

    $writable=is_writable($logfile);
    if($writable){
    echo "File Can Be Written to<br>";
    }
    else{
    echo "File Cannot Be Written to<br>";
    }

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



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

    }
    else{
    error_log("$logfile does not exist");
    }



    --
    Randy Jackson
    http://fourcolorexplosion.com
    Randy Guest

  2. Similar Questions and Discussions

    1. Problem writing to file.....charset I think
      I am having a problem writing to a file. I am trying to write the following to a file <cfset text = "#chr(1)##chr(0)##chr(8)#"> <cffile...
    2. writing rotation data to a file problem
      dear forum, i tried to write the camera position and rotation to a file, so i can use it in another programm. i am doing the following things:...
    3. problem writing a file
      Hi, I'm really stuck with this one - wondering if you can spot the problem? I think that it's a webserver problem that goes deeper than web.config....
    4. publishing Shockwave: problem writing file
      When publishing a DirectorMX movie with linked castlibs as a Shockwave, I get this Director error: Problem writing file: 'c:\myFolder\myDirFile':...
    5. A failure occurred writing to the resources file. Access is denied. -- RESX file is locked? -- WHY?
      Hi. This is an error that comes up fairly regularly when trying to run the "Rebuild All" command in a Solution that contains more than one...
  3. #2

    Default Re: Problem Writing To File

    ["Followup-To:" header set to comp.lang.php.]
    Randy Jackson wrote: 

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

    Put these at the top of your scripts
    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    ?>

    or change php.ini to have it on at all times.
     
    ^^^^^^^^^^^^
    Not that it matters for the problem at hand,
    but do you have "register globals" on?
     
    ^^^^^^
    Shouldn't this be only "\n" and let the OS do the translation?
    Again, it doesn't matter for your problem :-)

    [snip] 
    ^^^
    text-mode translation; use "ab" for binary-mode.


     

    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>";
    }
     

    Happy Bug Hunting :-)
    --
    USENET would be a better place if everybody read: | to mail me: simply |
    http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
    http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
    http://www.expita.com/nomime.html | and *NO* attachments. |
    Pedro Guest

  4. #3

    Default Re: Problem Writing To File

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

    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.
    Steven Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139