Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004
    Posts
    82

    Unanswered: fwrite() with folders

    So, i am running a script which uses the fwrite(); function to write some data into a html file. However this file is located in a new folder and:

    fwrite("servers/{$server}.html", "$login<br>\n");

    doesn't work. $server is a dynamic variable which changes dependant on the uses input, and no it still doesn't work when i replace {$server} with a static filename for example "servers/server12.html".

    Doesn't fwrite not write into folders. CHMOD for "/servers/" is 0777 and for the html file it is 0766. (Which isn't a prob).

    Thanks,

    Jordan

  2. #2
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    fwrite does not accept a file name as a parameter. It accepts a resource handle which is the result of a previous fopen(...) statement. See the following example from the PHP manual -
    PHP Code:
    <?php
    $filename 
    'test.txt';
    $somecontent "Add this to the file\n";

    // Let's make sure the file exists and is writable first.
    if (is_writable($filename)) {

        
    // In our example we're opening $filename in append mode.
        // The file pointer is at the bottom of the file hence 
        // that's where $somecontent will go when we fwrite() it.
        
    if (!$handle fopen($filename'a')) {
             echo 
    "Cannot open file ($filename)";
             exit;
        }

        
    // Write $somecontent to our opened file.
        
    if (fwrite($handle$somecontent) === FALSE) {
            echo 
    "Cannot write to file ($filename)";
            exit;
        }
        
        echo 
    "Success, wrote ($somecontent) to file ($filename)";
        
        
    fclose($handle);

    } else {
        echo 
    "The file $filename is not writable";
    }
    ?>

  3. #3
    Join Date
    Aug 2004
    Posts
    82
    thanks for that dude!

Posting Permissions

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