PHP filesize() 函數(shù)是什么?相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。
我們提供的服務(wù)有:網(wǎng)站設(shè)計、網(wǎng)站制作、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、平羅ssl等。為超過千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的平羅網(wǎng)站制作公司
filesize
作用:函數(shù)返回指定文件的大小
語法:
filesize(filename)
參數(shù):
filename:必需。規(guī)定要檢查的文件。
返回值:
返回文件大小的字節(jié)數(shù),如果出錯返回 FALSE 并生成一條 E_WARNING 級的錯誤。
filesize 示例
示例一
示例二
示例三
array( "UNIT" => "TB", "VALUE" => pow(1024, 4) ), 1 => array( "UNIT" => "GB", "VALUE" => pow(1024, 3) ), 2 => array( "UNIT" => "MB", "VALUE" => pow(1024, 2) ), 3 => array( "UNIT" => "KB", "VALUE" => 1024 ), 4 => array( "UNIT" => "B", "VALUE" => 1 ), ); foreach($arBytes as $arItem) { if($bytes >= $arItem["VALUE"]) { $result = $bytes / $arItem["VALUE"]; $result = str_replace(".", "," , strval(round($result, 2)))." ".$arItem["UNIT"]; break; } } return $result; } ?>
示例四
2 Gb) * For file size over PHP_INT_MAX (2 147 483 647), PHP filesize function loops from -PHP_INT_MAX to PHP_INT_MAX. * * @param string $path Path of the file * @return mixed File size or false if error */ function realFileSize($path) { if (!file_exists($path)) return false; $size = filesize($path); if (!($file = fopen($path, 'rb'))) return false; if ($size >= 0) {//Check if it really is a small file (< 2 GB) if (fseek($file, 0, SEEK_END) === 0) {//It really is a small file fclose($file); return $size; } } //Quickly jump the first 2 GB with fseek. After that fseek is not working on 32 bit php (it uses int internally) $size = PHP_INT_MAX - 1; if (fseek($file, PHP_INT_MAX - 1) !== 0) { fclose($file); return false; } $length = 1024 * 1024; while (!feof($file)) {//Read the file until end $read = fread($file, $length); $size = bcadd($size, $length); } $size = bcsub($size, $length); $size = bcadd($size, strlen($read)); fclose($file); return $size; }
看完上述內(nèi)容,你們掌握PHP filesize() 函數(shù)是什么的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!