SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, I just started learning PHP yesterday and I've already run into a problem which I can't seem to figure out.

    <?php
    $file = fopen("index.txt", "r");
    print($file);
    fclose($file);
    ?>

    Now, when I run that from my site I get a little message that says "Resource id #1". I want it to read everything from index.txt. All the files have been uploaded and the permission is set to 777. Can someone please help me?

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In your script $file only holds a reference to the opened file, you need to use fgets() or fread() to read the contents of the file.

    PHP Code:
    <?php 
    $file 
    fopen("index.txt""r"); 
    if(
    $file) {
    while(!
    feof($file)) {
    $data .= fgets($file4096);
    }
    print 
    $data;
    fclose($file);
    }
    else {
    print 
    "Error openening file"
    }
    ?>
    Which basically says if the file is opened successfully, while we haven't reached the end of the file, store the current line in the variable $data, then append each concurrent line to the var $data till the end of the file is reached.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •