Basic Filesize() call fails

This is a discussion on Basic Filesize() call fails within the PHP Language forums, part of the PHP Programming Forums category; I just CANNOT figure out what is wrong with this! ------ $op1f = fopen("./test.txt","r"); $op1 = ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-29-2005
IWP506@gmail.com
 
Posts: n/a
Default 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.filesize]: stat failed for Resource id #3
in C:\Program Files\Apache
Group\Apache2\htdocs\php\php\pickone\php\index.php on line 11

Warning: fread() [function.fread]: Length parameter must be greater
than 0. in C:\Program Files\Apache
Group\Apache2\htdocs\php\php\pickone\php\index.php on line 11

------


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

Thanks,
IWP506

Reply With Quote
  #2 (permalink)  
Old 05-29-2005
Daniel Tryba
 
Posts: n/a
Default Re: Basic Filesize() call fails

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


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...

Reply With Quote
  #3 (permalink)  
Old 05-29-2005
IWP506@gmail.com
 
Posts: n/a
Default Re: Basic Filesize() call fails

I knew it was something stupid.

Thanks,

IWP506

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:47 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0