I have the following code:
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
$dir = $root.'/mphp/124/upload/uploads/';
$files = array_diff(scandir($dir,2), array('..','.','.htaccess'));
foreach ($files as $key => $value) {
echo $value.','.filesize($value).'<br>';
}
?>
However PHP displays this error (with exception for one file which size is succesfully displayed):
Warning: filesize(): stat failed for /*name*/ in /*this php file*/ on line 6.
Why does this happen?
CodePudding user response:
I believe $value
is the name of the file ( without the path ) -- in other words you need the path the value. in this case filesize($dir . $value)
For reference I went and looked
https://www.php.net/manual/en/function.scandir
Returns an array of filenames on success
CodePudding user response:
You Can Use This Function
filesize('Your File Path' , 'Your File Name');