Read a full text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mague
    New Member
    • May 2007
    • 137

    Read a full text file

    I have got a website with a few friends from school(year8). We have got a website up. I want it so it looks for a textfile and reads and writes it into a textbox. It does do this. The only problem is that it doesn't read the whole file. It may read like 3 words out of 7 so its not that gud.

    This is my code[code=php]
    <div id="text2" style="position :absolute; overflow:hidden ; left:351px; top:192px; width:475px; height:671px; z-index:2"><div class="wpmd">
    <div><font class="ws12" face="Franklin Gothic Heavy">
    <?php
    $myFile = "HomeNews.t xt";
    $passw = fopen($myFile, "r");
    $pass = fread($passw, 5);
    while ( $line = fgets($passw, 1000) ) {
    echo($line);
    }[/code]

    I am using notepad on windows xp. And im using my friends server which he pays for and i think they use appach.

    Hopefully someone can help.
    Thanks alot
    Mague
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    Originally posted by Mague
    [php]
    <div id="text2" style="position :absolute; overflow:hidden ; left:351px; top:192px; width:475px; height:671px; z-index:2"><div class="wpmd">
    <div><font class="ws12" face="Franklin Gothic Heavy">
    <?php
    $myFile = "HomeNews.t xt";
    $passw = fopen($myFile, "r");
    $pass = fread($passw, 5);
    while ( $line = fgets($passw, 1000) ) {
    echo($line);
    }
    [/php]
    Mague
    Try changing the line:
    [php]
    $pass = fread($passw, 5) ;
    [/php]

    To:
    [php]
    $pass = fread($passw, filesize($passw ))
    [/php]

    I found this on the php site. There maybe more helpful information there.

    Cheers
    nathj

    Comment

    • Mague
      New Member
      • May 2007
      • 137

      #3
      Originally posted by nathj
      Try changing the line:
      [php]
      $pass = fread($passw, 5) ;
      [/php]

      To:
      [php]
      $pass = fread($passw, filesize($passw ))
      [/php]

      I found this on the php site. There maybe more helpful information there.

      Cheers
      nathj
      Thanks Alot this code didn't work but led me on to find this code
      $contents = fread($handle,f ilesize); which does work

      thanks heaps
      Mague

      Comment

      • nathj
        Recognized Expert Contributor
        • May 2007
        • 937

        #4
        Originally posted by Mague
        Thanks Alot this code didn't work but led me on to find this code
        $contents = fread($handle,f ilesize); which does work

        thanks heaps
        Mague

        that;s my mistake - the filesize function takes the filename as the parameter not the file handle - that's my fault. Sorry, at least it's working now though.

        All the best with the rest of the project.

        Cheers
        nathj

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, Mague.

          Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

          Comment

          Working...