Results 1 to 7 of 7

Thread: Resource id #2

  1. #1

    Thread Starter
    Hyperactive Member dandono's Avatar
    Join Date
    Aug 2004
    Location
    Cornwall, UK
    Posts
    485

    Resource id #2

    hi, i have made this code that reads a text doc and echos it to the page. here is my code:
    PHP Code:
    <?
    $user = $_GET['user'];
    echo '<html>
    <head>
    <title>Dans Web Server 2005!</title>
    </head>
    <body>
    <h1>';
    echo fopen($user . "fn.txt","r");
    echo '</h1>
    </body>
    </html>'
    ?>
    it is ment to echo what is in a text file (username and "fn.txt") but insted it echos Resource id #2. what is wrong with my code?
    thanks, dandono
    If there is only one perfect person in the universe, does that make them imperfect?

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Resource id #2

    Once you have opened a file with fopen, a resource is returned. The resource holds all the information about the file, like the current position of the pointer, its name, its handle and other things.

    So once you have opened your file you must use functions such as fread() and fgets() to read the contents, which all take a file pointer resource as one of their parameters.

    In your case, as you want to just dump the entire file, you should use the fpassthru() function.
    PHP Code:
    <?php 
        $user 
    $_GET['user']; 
        
        
    // assign the resource to a variable
        
    if (! $fhwnd fopen($user 'fn.txt','r')) {
            die(
    'Failed to open file.');
        }
    ?>
    <html>
        <head>
            <title>Dans Web Server 2005!</title>
        </head>
        <body>
            <h1><?php fpassthru($fhwnd?></h1>
        </body>
    </html>
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Hyperactive Member dandono's Avatar
    Join Date
    Aug 2004
    Location
    Cornwall, UK
    Posts
    485

    Re: Resource id #2

    how would i be able to do this when opening more than 1 text doc?
    If there is only one perfect person in the universe, does that make them imperfect?

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Resource id #2

    I'm not entirely sure what you mean. But, you can have more than one file open at a time. Just assign each resource to a different varaible. Don't forget to close the file after you have finished with it by using the fclose() function.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Hyperactive Member dandono's Avatar
    Join Date
    Aug 2004
    Location
    Cornwall, UK
    Posts
    485

    Re: Resource id #2

    i ment to echo one files contents and then another files contents and so on
    If there is only one perfect person in the universe, does that make them imperfect?

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Resource id #2

    PHP Code:
    <?php 
        $user 
    $_GET['user']; 
        
        
    // assign the resource to a variable
        
    if (! $fhwnd1 fopen($user 'file1.txt','r')) {
            die(
    'Failed to open file 1.');
        }

        if (! 
    $fhwnd2 fopen($user 'file2.txt','r')) {
            die(
    'Failed to open file 2.');
        }
    ?>
    <html>
        <head>
            <title>Dans Web Server 2005!</title>
        </head>
        <body>
            <h1><?php fpassthru($fhwnd1?></h1>
            <h1><?php fpassthru($fhwnd2?></h1>
        </body>
    </html>
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    Hyperactive Member dandono's Avatar
    Join Date
    Aug 2004
    Location
    Cornwall, UK
    Posts
    485

    Re: Resource id #2

    thanks, dandono.
    If there is only one perfect person in the universe, does that make them imperfect?

Posting Permissions

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



Click Here to Expand Forum to Full Width