Basic Filesize() call fails

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • IWP506@gmail.com

    Basic Filesize() call fails

    I just CANNOT figure out what is wrong with this!

    ------

    $op1f = fopen("./test.txt","r");
    $op1 = fread($op1f, filesize($op1f) );

    ------



    my file text.txt is in the same dir as the php file. I get the
    following errors on run:

    ------

    Warning: filesize() [function.filesi ze]: stat failed for Resource id #3
    in C:\Program Files\Apache
    Group\Apache2\h tdocs\php\php\p ickone\php\inde x.php on line 11

    Warning: fread() [function.fread]: Length parameter must be greater
    than 0. in C:\Program Files\Apache
    Group\Apache2\h tdocs\php\php\p ickone\php\inde x.php on line 11

    ------


    I know it's something stupid I'm doing, but I simply can't figure it
    out!

    Thanks,
    IWP506

  • Daniel Tryba

    #2
    Re: Basic Filesize() call fails

    IWP506@gmail.co m wrote:[color=blue]
    > $op1f = fopen("./test.txt","r");
    > $op1 = fread($op1f, filesize($op1f) );
    >
    > Warning: filesize() [function.filesi ze]: stat failed for Resource id #3
    > in C:\Program Files\Apache
    > Group\Apache2\h tdocs\php\php\p ickone\php\inde x.php on line 11
    >
    > I know it's something stupid I'm doing, but I simply can't figure it
    > out![/color]

    Read the manual page (http://nl2.php.net/filesize) carefully, It's
    contains the prototype of filesize():
    int filesize ( string filename )

    Thus the only argument to filesize should be a string containing the
    name of the file. You error reports that the argument passed in your
    script is a resource and thus not a string.

    BTW you lack any errorhandling, so an other error will appear to the
    user in case eg test.txt doesn't exist or is not readable...

    Comment

    • IWP506@gmail.com

      #3
      Re: Basic Filesize() call fails

      I knew it was something stupid.

      Thanks,

      IWP506

      Comment

      Working...