space index.php 7-14,disk_free_space()

disk_free_space()

(PHP 4 >= 4.1.0, PHP 5, PHP 7)

返回目錄中的可用空間

說明disk_free_space(string$directory):float

給出一個包含有一個目錄的字符串,本函數將根據相應的文件系統或磁盤分區返回可用的字節數。

參數$directory文件系統目錄或者磁盤分區。Note:

如果指定了文件名而不是文件目錄,這個函數的行為將并不統一,會因操作系統和 PHP 版本而異。

返回值

以浮點返回可用的字節數,或者在失敗時返回FALSE。

范例

Example #1disk_free_space()例子<?php

// $df 包含根目錄下可用的字節數

$df = disk_free_space("/");

//在 Windows 下:

$df_c = disk_free_space("C:");

$df_d = disk_free_space("D:");

?>

注釋Note:此函數不能作用于遠程文件,被檢查的文件必須是可通過服務器的文件系統訪問的。

參見Transformation is possible WITHOUT using loops:

$bytes = disk_free_space(".");

$si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB');

$base = 1024;

$class = min((int)log($bytes , $base) , count($si_prefix) - 1);

echo $bytes . '
';

echo sprintf('%1.2f', $bytes / pow($base,$class)) . ' '. $si_prefix[$class] . '
';

?>Nice, but please be aware of the prefixes.

SI specifies a lower case 'k' as 1'000 prefix.

It doesn't make sense to use an upper case 'K' as binary prefix,

while the decimal Mega (M and following) prefixes in SI are uppercase.

Furthermore, there are REAL binary prefixes since a few years.

Do it the (newest and recommended) "IEC" way:

KB's are calculated decimal; power of 10 (1000 bytes each)

KiB's are calculated binary; power of 2 (1024 bytes each).

The same goes for MB, MiB and so on...

Feel free to read:

http://en.wikipedia.org/wiki/Binary_prefix$si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' );

you are missing the petabyte after terabyte

'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB'

should look like

'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'Another easy way to convert bytes to human readable sizes would be this:

function HumanSize($Bytes)

{

$Type=array("", "kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta");

$Index=0;

while($Bytes>=1024)

{

$Bytes/=1024;

$Index++;

}

return("".$Bytes." ".$Type[$Index]."bytes");

}

?>

It simply takes the $Bytes and divides it by 1024 bytes untill it's no longer over or equal to 1024, meanwhile it increases the $Index to allocate which suffix belongs to the return (adding 'bytes' to the end to save some space).

You can easily modify it so it's shorter, but I made it so it's more clearer.

Nitrogen.Note that disk_free_space() does an open_basedir check.With respect to Linux filesystems, I'll point out that this function returns the space available in the current volume or mountpoint, not the total physical disk space. That is, this function used on the '/root' volume shows the free space in /root, which is different from '/home', and so on.<?php

function size($size, array $options=null) {

$o = [

'binary'=> false,

'decimalPlaces'=> 2,

'decimalSeparator'=> '.',

'thausandsSeparator'=> '',

'maxThreshold'=> false, // or thresholds key

'sufix'=> [

'thresholds'=> ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'],

'decimal'=> ' {threshold}B',

'binary'=> ' {threshold}iB'

]

];

if ($options !== null)

$o = array_replace_recursive($o, $options);

$count = count($o['sufix']['thresholds']);

$pow = $o['binary'] ? 1024 : 1000;

for ($i = 0; $i < $count; $i++)

if (($size < pow($pow, $i + 1)) ||

($i === $o['maxThreshold']) ||

($i === ($count - 1))

)

return

number_format(

$size / pow($pow, $i),

$o['decimalPlaces'],

$o['decimalSeparator'],

$o['thausandsSeparator']

) .

str_replace(

'{threshold}',

$o['sufix']['thresholds'][$i],

$o['sufix'][$o['binary'] ? 'binary': 'decimal']

);

}

var_dump(size(disk_free_space('/')));

// string(8) "14.63 GB"

var_dump(size(disk_free_space('/'), ['binary'=> true]));

// string(9) "13.63 GiB"

var_dump(size(disk_free_space('/'), ['maxThreshold'=> 2]));

// string(11) "14631.90 MB"

var_dump(size(disk_free_space('/'), ['binary'=> true, 'maxThreshold'=> 2]));

// string(12) "13954.07 MiB"

?>On Windows, this also works with distant files, by using their full network path.

For instance, this will give the % of free disk space on the share "dir" from remote host "server" :

$path = "\\\\server\\dir";

echo(floor(100 * disk_free_space($disk) / disk_total_space($disk)));

?>

It can also work with drive letters mapped to a network path in certain cases.

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/393977.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/393977.shtml
英文地址,請注明出處:http://en.pswp.cn/news/393977.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

云專網和云專線的區別_企業更適合互聯網專線還是云專線聯網?

隨著云計算、移動應用及全球化的發展&#xff0c;縱橫企業專網20年的MPLS專線弊端逐漸暴露&#xff0c;MPLS專線越來越難以滿足企業的業務發展需求&#xff0c;而云計算、SaaS及移動應用具有天然的互聯網屬性。為什么“互聯網”可以取代專線?互聯網的持續發展&#xff0c;為取…

composer安裝thinkphp

https://getcomposer.org/Composer-Setup.exe 正常安裝composer以后,執行composer create-project topthink/thinkphp myapp安裝thinkphp.轉載于:https://www.cnblogs.com/lijurui/p/6362012.html

wordpress 插件_如何為您的Web應用程序創建WordPress插件

wordpress 插件by Feedier by Alkalab由Feedier通過Alkalab 如何為您的Web應用程序創建WordPress插件 (How to create a WordPress plugin for your web app) Today, we are going to see how to create a very simple WordPress plugin for any web app that needs to insert…

Android 軟鍵盤相關問題

1. windowSoftInputMode屬性的使用 Android使用windowSoftInputMode來控制Activity 的主窗口與包含屏幕軟鍵盤的窗口的交互方式。 該屬性的設置影響兩個方面&#xff1a; 當 Activity 成為用戶注意的焦點時軟鍵盤的狀態 — 隱藏還是可見。對 Activity 主窗口所做的調整 — 是否…

git php框架,如何用Git安裝TP框架

本篇文章主要給大家介紹如何用Git安裝Thinkphp框架。關于TP框架的安裝&#xff0c;想必大家都知道較為常見的方式是通過composer安裝tp框架。首先簡單的給大家介紹下Git和TP框架。Git是一個開源的分布式版本控制系統&#xff0c;可以快速&#xff0c;高效地處理從小型到大型項目…

C#EF中,使用類似于SQL中的% 模糊查詢

最近在做項目的時候需要使用到模糊查詢,但是后臺使用EF寫的 而不是ADO或者是Dapper,如果是這樣的話,我們就可以使用Sql語句直接進行模糊查詢 現在我們需要在LINQ中使用類似于模糊查詢 在EF中有兩個方法:StartsWith()和EndWith() StartsWith(): 在轉到定義時 我們可以看見,這個方…

android toast居中顯示_Android Toast 設置到屏幕中間,自定義Toast的實現方法,及其說明...

Android Toast用于在手機屏幕上向用戶顯示一條信息&#xff0c;一段時間后信息會自動消失。信息可以是簡單的文本&#xff0c;也可以是復雜的圖片及其他內容(顯示一個view)。1.簡單用法Toast.makeText(midlet.getApplicationContext(), "用戶名不能為空", Toast.LENG…

leetcode103. 二叉樹的鋸齒形層次遍歷(bfs)

給定一個二叉樹&#xff0c;返回其節點值的鋸齒形層次遍歷。&#xff08;即先從左往右&#xff0c;再從右往左進行下一層遍歷&#xff0c;以此類推&#xff0c;層與層之間交替進行&#xff09;。例如&#xff1a; 給定二叉樹 [3,9,20,null,null,15,7],3/ \9 20/ \15 7 返回…

LintCode Find the Weak Connected Component in the Directed Graph

原題鏈接在這里&#xff1a;http://www.lintcode.com/en/problem/find-the-weak-connected-component-in-the-directed-graph/ 題目&#xff1a; Find the number Weak Connected Component in the directed graph. Each node in the graph contains a label and a list of its…

簡單了解tengine

Tengine是由淘寶網發起的Web服務器項目。它在Nginx的基礎上&#xff0c;針對大訪問量網站的需求&#xff0c;添加了很多高級功能和特性。最終目標是打造一個高效、穩定、安全、易用的Web平臺。1、基本的HTTP服務器特性1.處理靜態文件&#xff0c;索引文件以及自動索引&#xff…

服務器創建多個dhcp服務_如何在15分鐘內創建無服務器服務

服務器創建多個dhcp服務by Charlee Li通過李李 如何在15分鐘內創建無服務器服務 (How to create a serverless service in 15 minutes) The word “serverless” has been popular for quite a while. When Amazon released the AWS Lambda service in 2015, many tools emerg…

php snoopy視頻教程,php的Snoopy類

用了兩天這個類&#xff0c;發現很好用。獲取請求網頁里面的所有鏈接&#xff0c;直接使用fetchlinks就可以&#xff0c;獲取所有文本信息使用fetchtext(其內部還是使用正則表達式在進行處理)&#xff0c;還有其它較多的功能&#xff0c;如模擬提交表單等。使用方法&#xff1a…

網頁解析 css

網頁解析 css轉載于:https://www.cnblogs.com/guozepingboke/p/10792298.html

如何看pg數據庫版本號_查看pg數據庫版本

PostgreSQL 基本命令鏈接&#xff1a;http://blog.itpub.net/28602568/viewspace-1841163/標題&#xff1a;PostgreSQL 基本命令作者&#xff1a;&#xff4c;ōττ&#xff52;&#xff59;©版權所有[文章允許轉載,但必須以鏈接方式注明源地址,否則追究法律責任.]安裝步…

leetcode1091. 二進制矩陣中的最短路徑(bfs)

在一個 N N 的方形網格中&#xff0c;每個單元格有兩種狀態&#xff1a;空&#xff08;0&#xff09;或者阻塞&#xff08;1&#xff09;。一條從左上角到右下角、長度為 k 的暢通路徑&#xff0c;由滿足下述條件的單元格 C_1, C_2, ..., C_k 組成&#xff1a;相鄰單元格 C_i …

lock和synchronized的同步區別與選擇

區別如下&#xff1a; 1. lock是一個接口&#xff0c;而synchronized是java的一個關鍵字&#xff0c;synchronized是內置的語言實現&#xff1b;&#xff08;具體實現上的區別在《Java虛擬機》中有講解底層的CAS不同&#xff0c;以前有讀過現在又遺忘了。&#xff09; 2. syn…

首頁顯示登陸用戶名php,首頁登錄后怎么在首頁顯示用戶名以及隱藏登錄框?

該樓層疑似違規已被系統折疊 隱藏此樓查看此樓index.php&#xff1a;登錄頁面用戶名&#xff1a;密碼&#xff1a;沒有賬號&#xff1f;立即注冊——————————————————————————doaction.php&#xff1a;header("Content-type:text/html;charsetutf…

react中使用構建緩存_通過在React中構建Tic Tac Toe來學習ReasonML

react中使用構建緩存3. 7. 2018: UPDATED to ReasonReact v0.4.23. 7. 2018&#xff1a;更新為ReasonReact v0.4.2 You may have heard of Reason before. It’s a syntax on top of OCaml that compiles to both readable JavaScript code and to native and bytecode as well…

echart vue 圖表大小_vue里echarts自適應窗口大小改變

echarts的圖表提供了一個resize方法可以自適應屏幕窗口改變&#xff0c;而重新渲染圖表大小的功能。因此我們只要監聽瀏覽器的窗口改變的resize事件&#xff0c;再結合echarts的圖表&#xff0c;就可以實現我們想要的功能了。如果是單個圖表的情況的話用window.onresize myCha…

用js檢測文本框中輸入的是否符合條件并有錯誤和正確提醒

<!DOCTYPE html> <html><head><meta charset"utf-8"><title>捕獲異常</title></head><script type"text/javascript">function my_func(){try{xdocument.getElementById("input_id").value;ale…