$db = Sys::getdb();
$dir="D:\phpStudy\WWW\caxa";
$file=array_diff(scandir($dir),array('..','.'));
foreach($file as $v){
$name = iconv('gbk' , 'utf-8' , $v );
$size = self::getRealSize(filesize('D:\phpStudy\WWW\caxa/'.$v));
$type = 0;
$db->insert('bookname',array('bookname'=>$name,'size'=>$size,'type'=>$type));
$txt .= $name.',';
}
$myfile = fopen(KO_ROOT_PATH."/data/linchuang.txt", "a+");
fwrite($myfile, $txt);
fclose($myfile);
echo "遍历完毕";
}
// 单位自动转换函数
function getRealSize($size)
{
$kb = 1024; // Kilobyte
$mb = 1024 * $kb; // Megabyte
$gb = 1024 * $mb; // Gigabyte
$tb = 1024 * $gb; // Terabyte
if($size < $kb)
{
return $size." B";
}
else if($size < $mb)
{
return round($size/$kb,2)." KB";
}
else if($size < $gb)
{
return round($size/$mb,2)." MB";
}
else if($size < $tb)
{
return round($size/$gb,2)." GB";
}
else
{
return round($size/$tb,2)." TB";
}
}