SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I'm trying to get data from a file ( grabbing everything ) then print it out.

    How do i do that?
    thanks

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this...

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
    int fpassthru(int filepath/goes/here.txt);
    [/code]

    I could be wrong...let me know if it works. That command should print out the entire file from beginning to end...




    ------------------
    Chris Bowyer chris@mycoding.com
    MyCoding.com: Visit for Launch Notification!
    DomainMailings.com: Who Says All The Good Ones Are Taken?
    MovieForums.com: Talk About Your Favorite Flicks!

  3. #3
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Not quite, TWTCommish. fpassthru takes a file handle as a parameter -- not a filename.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
    $file = fopen("/path/to/file.txt", "r");
    fpassthru($file);
    fclose($file);
    [/code]

    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

    [This message has been edited by kyank (edited July 31, 2000).]

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My mistake, and another testament to your greatness, O Kevin.



    ------------------
    Chris Bowyer chris@mycoding.com
    MyCoding.com: Visit for Launch Notification!
    DomainMailings.com: Who Says All The Good Ones Are Taken?
    MovieForums.com: Talk About Your Favorite Flicks!

  5. #5
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I can't seem to get it to print out everything, with the lines too.
    As in, it prints are everything on 1 line.

    I changed file to $file as it produced an error.
    but then after that, it showed the data on 1 whole line ( instead of several lines ) and produced an error thereafter.

    Warning: Unable to find file identifier 1 in /home/nortiq/www/temp.php on line 4

    Please Help

    thanks

  6. #6
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    First of all you're right, it should have been "$file", not "file".

    The error message you're getting seems to be coming from the fact that fpassthru() implicitly closes the file after outputting its contents. Thus, the fclose() line is unneccessary.

    As for why the contents of the file are appearing on one line, that's just Web browsers for you. If you choose View Source in your browser, you'll see that the file was actually output correctly. It's just that the Web browser is reading it as a Web page and thus flows all the lines together.

    If you just want to display the contents of the file (i.e. you have no HTML elements in the page), you can tell the browser to interpret the page as a plain text file instead by adding the following line to the top of your PHP script:

    header("Content-Type: text/plain");

    Alternatively, you can surround the file's contents with &lt;PRE&gt;...&lt;/PRE&gt; to preserve the end-of-lines and extra whitespace.

    If neither of these options is acceptable, let me know and I'll show you the code that will read the file into a PHP variable and convert it into the HTML code neccessary to display it.


    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

  7. #7
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WOW.
    Thanks! I really apprectiated the help.


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
  •