好吧所以我在主根上有一个php文件,我试图在我服务器上的较低文件夹中获取文件的文件大小。
示例:http://website.com/myphpfile.php 试图访问:http://website.com/movies/ [包含所有内容]
我一直得到0或一些随机数,但我不能让它产生每个文件的大小。
// Opens directory
$myDirectory = opendir("./movies");
// Gets each entry
while($entryName = readdir($myDirectory)) {
$dirArray[] = $entryName;
}
我正在使用此代码段:
function size_readable($size, $max = null, $system = 'si', $retstring = '%01.2f %s')
{
// Pick units
$systems['si']['prefix'] = array('B', 'K', 'MB', 'GB', 'TB', 'PB');
$systems['si']['size'] = 1000;
$systems['bi']['prefix'] = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB');
$systems['bi']['size'] = 1024;
$sys = isset($systems[$system]) ? $systems[$system] : $systems['si'];
// Max unit to display
$depth = count($sys['prefix']) - 1;
if ($max && false !== $d = array_search($max, $sys['prefix'])) {
$depth = $d;
}
// Loop
$i = 0;
while ($size >= $sys['size'] && $i < $depth) {
$size /= $sys['size'];
$i++;
}
return sprintf($retstring, $size, $sys['prefix'][$i]);
}
我的问题是如何调用这些文件?
我知道这是错的,但应该是什么?
$thefilesize = size_readable(filesize($entryName));
OR
有人可以编写/编辑此代码,以帮助我了解正在发生的事情以及它正在抓取的地方吗?
答案 0 :(得分:3)
$ entryName只会引用文件名。如果要引用该文件,还需要包含该目录。
$thefilesize = size_readable(filesize($myDirectory .'/' . $entryName));