File_put_content

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    File_put_content

    I want Save "data.txt" File In Folder "/data" as name 'datax.txt'

    Is It possible With Below Code?

    $file='data.txt';
    $folder='/data';
    file_put_content($file, $folder);

    #2
    not with that code as its full of syntax errors.

    but this would work
    PHP Code:
    <?php
    $file 
    'data/data.txt';
    $string 'A Testing Message Inside A Txt File.'//Can Be Blank also.
    file_put_contents($file$string);
    ?>
    //
    //
    //
    to append to file this way you would do
    PHP Code:
    <?php
    $file 
    'data/data.txt';
    $string 'A Testing Message Inside A Txt File.'//Can Be Blank also.
    file_put_contents($file$stringFILE_APPEND LOCK_EX); // LOCK_EX would stop anyone else writing to the file at the same time.
    ?>
    //
    //
    //
    although im not sure it actually sets the file permission for you. so you could add to end of that.
    PHP Code:
    chmod($file0777);
    //
    //
    // 
    <?php
    include ('Ghost');
    if ($Post == true) {
    echo '

    sigpic
    alt='coding-talk.com!!' />';
    echo 'Sharing Is Caring!';
    } else {
    echo '

    alt='the username GHOST has been comprimised!' />';
    echo 'OMG SOMEBODY HELP ME!!';
    }
    ?>

    Comment


      #3
      file_put_contents function context was only added to PHP at version 5.0.0. This function is just a PHP Wrapper and is actually identical to calling fopen(), fwrite() and fclose() successively to write data to a file. The ability to lock a file while it is being used with the LOCK_EX flag was added in PHP 5.0.1.

      Use file_put_contents($file, $data, FILE_APPEND); to append date to the end of a file.

      Regards,
      Rob

      Comment

      Working...
      X