Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Writing to files and retrieving the value

  1. #1
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Writing to files and retrieving the value

    Hello , heres my script and i don't understand what's wrong with it -

    <html>
    <body>
    <?php
    $file="file.txt";
    $fileo = fopen($file,"a");
    $filew = fwrite($fileo,"Rocks Are Cool");
    $filer = fread($fileo);
    $filec = fclose($file);
    echo $filer;
    ?>
    </body>
    </html>

    So whats wrong with it ?

  2. #2
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Cmon guys i really don't mind havin some help here

  3. #3
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    What error messages do you get?
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  4. #4
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It simply shows nothing on the page...

  5. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Replace fread (which returns a handle) with file_get_contents.
    - Mike

  6. #6
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Whats the difference ?

  7. #7
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    not sure. but it always seems to work better than fread.
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  8. #8
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    What do you mean ?

  9. #9
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    I Mean, use this...
    PHP Code:
    <html>
     <body>
     <?php
     $file
    ="file.txt";
     
    $fileo fopen($file,"a");
     
    fwrite($fileo,"Rocks Are Cool");
     
    fclose($file);
     
    $filer file_get_contents($file);
     echo 
    $filer;
     
    ?>
     </body>
     </html>
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  10. #10
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok give me some time to work it out (10 min) - while then tell me did that mean that all that time i made only one mistake...?

Bookmarks

Posting Permissions

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