php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43166 filesize does not work ever
Submitted: 2007-10-31 19:14 UTC Modified: 2007-10-31 21:16 UTC
From: shashank dot araokar at gmail dot com Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 5.2.4 OS: Windows XP
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: shashank dot araokar at gmail dot com
New email:
PHP Version: OS:

 

 [2007-10-31 19:14 UTC] shashank dot araokar at gmail dot com
Description:
------------
The filesize() function always fails, even if the file opens up properly and without warnings (it has been verified that there is no file access issue and also that PHP knows that the file is there).

The warning is Warning filesize: stat failed for resource #xxx etc.

Please note that it has been confirmed at absolutely all permissions have been granted to both the directory and the file and that the file is existing and can also be opened by PHP.

Either this is a serious error or a function as ordinary as filesize() is made too complex to use, which in itself is a problem!

This has been tested on several servers. If the file does not exist, a proper warning is thrown, meaning that non-existence of the file is not any issue.

Reproduce code:
---------------
<?php
	$file=fopen("uploads/test.txt","rb");
	$contents=fread($file, filesize($file));
	fclose($file);
?>

Expected result:
----------------
(no output, no warnings, no errors!)

Actual result:
--------------
Warning: filesize() [function.filesize]: stat failed for Resource id #3 in /www/110mb.com/w/a/v/i/c/l/e/_/wavicle/htdocs/test.php on line 4

Warning: fread() [function.fread]: Length parameter must be greater than 0 in /www/110mb.com/w/a/v/i/c/l/e/_/wavicle/htdocs/test.php on line 4

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-31 19:23 UTC] carsten_sttgt at gmx dot de
According to the PHP manual, you must use a string with the filepath as parameter for filesize(), not a ressource.

Regards,
Carsten
 [2007-10-31 21:16 UTC] felipe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

http://www.php.net/filesize
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Aug 16 05:00:03 2025 UTC