SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: i am an idiot

  1. #1
    SitePoint Member
    Join Date
    May 2001
    Location
    NJ
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well i worked on this all day trying to figure it out before i posted it.. but here goes...

    an excerpt of my code follows. the problem is that i keep getting "Doh!" which means that the fread is not working (i also tried fgets). i really have no idea why. i have already created the file "phillies.txt" and it has data in it. i made sure the path is correct. for the love of god i cannot figure out what the problem is. please help!

    ...

    $p = "phillies.txt";

    $p_file = @fopen($p, "r") or die("Couldn't open file.");
    $p_string = @fread($p_file, filesize($p)) or die("Doh!");
    $p_count = (int) $p_string;

    ...

    --Craig

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    remove the @'s, does it then give an error?

  3. #3
    SitePoint Member
    Join Date
    May 2001
    Location
    NJ
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    no

    still does not work..

    any more ideas?

  4. #4
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could try giving different permissions for opening the file.

    Instead of r you could try r++ which I think is read and write.

    Probably not this, but you could give it a try.

  5. #5
    Not Bad, eh? Justin Sampson's Avatar
    Join Date
    Aug 2000
    Location
    N.S., Canada
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For reading and writing use "r+" It should work!

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    remove all instances of 'or die()' and '@'.

  7. #7
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure that @ is cause the problem, as far I know its purpose is indicate to php do not show any warning or error message.

    Paul

  8. #8
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also from php manual:

    'r' - Open for reading only; place the file pointer at the beginning of the file.

    'r+' - Open for reading and writing; place the file pointer at the beginning of the file.

    'w' - Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.

    'w+' - Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.

    'a' - Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.

    'a+' - Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
    Paul

  9. #9
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe what Philip is attempting to do is to have cwillsjr report to us the exact error message. They are build into the language for a purpose!


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
  •