Reputation: 43569
Other than turning warnings off.. what can I do in my code to get rid of this error:
warning: filesize() [function.filesize] stat failed for .... on line 152
The code is:
$store_filesize = filesize($file->filepath);
Upvotes: 4
Views: 19115
Reputation: 50602
Don't call filesize
unless the file actually exists:
$store_filesize = is_file($file->filepath) ? filesize($file->filepath) : 0;
Docs for is_file
: http://php.net/manual/en/function.is-file.php
:)
Upvotes: 3
Reputation: 5661
$store_filesize = @filesize($file->filepath);
if ($store_filesize === FALSE) {
throw new \Exception('filesize failed');
}
Upvotes: 3
Reputation: 26719
Check if the file exists, is file and is readable
if (is_readable($file->filepath)) {
$store_filesize = filesize($file->filepath);
}
Upvotes: 1
Reputation: 146310
Remember to check for null
:
if($file->filepath != null){
$store_filesize = filesize($file->filepath);
}
Upvotes: 1
Reputation: 6884
I'm not sure if this is what you want (e.g. I'm not clear if you want to work out why it's happening and work around it) but if you are just looking to suppress errors you can usually use @ in front of the function name.
e.g.
$store_filesize = @filesize($file->filepath);
Upvotes: 6