Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    North East England
    Posts
    853
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Open and print contents of a file?

    This may be utterly moronic, I was messing about and thought I'd be able to open and print the contents of a file using the followng:
    PHP Code:
    <?php
    $content 
    fopen ("path/url""r");
    print 
    "$content";
    ?>
    Actually the result is Resource ID#1. So obviously not, why?

    [+] Computer/PC issues [+] Silverpaw3D
    ------------------------------------------------
    Never buy a dwarf with learning disabilities...

    ...it's not big, and it's not clever.

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    <? 

        
    // conect to handle a file 
        
    $file_handler fopen("http://www.php.net/""r"); 

        
    /* to open a local file use this instead 
            $file_handler = fopen("data.txt", "r"); 
        */ 

        // read the contents 
        
    $contents fread($file_handlerfilesize($file)); 

        
    // close the file 
        
    fclose($file_handler); 

        
    // print the contents on your page 
        
    echo $contents
    ?>
    Last edited by Nightfire; 03-30-2003 at 11:40 PM.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    North East England
    Posts
    853
    Thanks
    0
    Thanked 0 Times in 0 Posts
    YAY!
    PHP Code:
    <?php
    $filename 
    "path";
    $handle fopen ($filename"r");
    $contents fread ($handlefilesize ($filename));
    fclose ($handle);
    print 
    "$contents";
    ?>
    [+] Computer/PC issues [+] Silverpaw3D
    ------------------------------------------------
    Never buy a dwarf with learning disabilities...

    ...it's not big, and it's not clever.


  •  

    Posting Permissions

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