How to get the size of disk partition through php file system function

黄舟
Release: 2023-03-07 19:50:01
Original
2983 people have browsed it

How to get the size of the disk partition through the php file system function

The file system function can not only operate directories and files, but also obtain directories. File-related information, then whether it is possible to obtain the size of the disk partition!

The disk_total_sapce() function is used to obtain the size of the disk partition, and the disk_free_space() function is used to obtain the remaining space of the disk partition.

disk_total_space() function: Get the disk size of a directory. The syntax format is as follows:

float disk_total_space(string directory)
Copy after login

This function returns the corresponding file system or disk distinction based on a directory string provided by the parameter directory. All bytes.

Note:

This function cannot be used on remote files, and the files it detects must pass the server File system access!

disk_free_space() function: Get the available space of a directory. The syntax format is as follows:

float disk_free_space(string directory)
Copy after login

Parameter directory is used to specify the file system or disk distinction!

Explanation:

This function returns the total size of the disk partition where the directory is located. Therefore, if you give different directories of the same disk partition as parameters, the results will be exactly the same!

Application Example

This example uses the disk_total_space() function to obtain the disk partition size. The specific code is as follows:

(1) Create a php file, add a form, set a text box, submit button, use the POST method, and submit to this page.

(2) Obtain the directory path for form submission through $_POST, and first determine whether the obtained directory is reasonable. Then the obtained string is encoded and converted through the iconv() function, and then the obtained string is intercepted. Get the referee partition where the directory is located, and use the disk_total_space() function to get the size of the disk partition. Finally, use the opendir() function and readdir() function to read the contents of the submitted directory. The specific code is as follows:

文件名称:

"; echo $_POST['file_name']."目录下的内容:"."
"; $i = 0; $list = opendir($file_name); //打开目录 while($read_list = readdir($list)){ //读取目录 $i++; echo "$i:".iconv("gb2312","utf-8",$read_list)."
"; //输出目录中的内容 } closedir($list); //关于目录 }else{ echo ""; } }else{ echo ""; } }
Copy after login

The above output results are as follows:

How to get the size of disk partition through php file system function

Description:

strripos() function Used to determine the last occurrence of a specified string in another string. Through this function, you can get the last position of the specified string A in another string B. The return value is int type. Based on the return value, string B can be intercepted using string A as the dividing point. The substr() function needs to be applied when performing interception operations.

$len = strripos($file_name,":"); //截取字符串 $dir = substr($file_name,0,$len+1); //获取提交目录所在磁盘
Copy after login

The above is the detailed content of How to get the size of disk partition through php file system function. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!