


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)
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)
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:
<form name="form1" action="6.php" method="post"> 文件名称: <input name="file_name" type="text"> <input type="submit" name="Submit" value="提交"> </form> <?php header("Content-Type:text/html; charset=utf-8"); if ($_POST['file_name']){ if($_POST['file_name']!="" && is_file($_POST['file_name'])==false){ $file_name = iconv("utf-8","gb2312",$_POST['file_name']); // 编码格式转换 if (file_exists($file_name)){ //判断目录是否存在 $len = strripos($file_name,":"); //截取字符串 $dir = substr($file_name,0,$len+1); //获取提交目录所在磁盘 $filesize_z = disk_total_space($dir); //获取目录大小 $filesize_z = number_format($filesize_z/(1024*1024*1024),2,".",""); //数字的格式化 $filesize_s = disk_free_space($dir); //获取裁判剩余空间 $filesize_s = number_format($filesize_s/(1024*1024*1024),2,".",""); //字节的格式化 echo "本地磁盘(".$dir.") 总大小:".$filesize_z." GB 可用空间:".$filesize_s."GB <br><br>"; echo $_POST['file_name']."目录下的内容:"."<br>"; $i = 0; $list = opendir($file_name); //打开目录 while($read_list = readdir($list)){ //读取目录 $i++; echo "$i:".iconv("gb2312","utf-8",$read_list)."<br>"; //输出目录中的内容 } closedir($list); //关于目录 }else{ echo "<script>alert('目录不存在!');</script>"; } }else{ echo "<script>alert('请输入正确的目录路径!');</script>"; } }
The above output results are as follows:
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); //获取提交目录所在磁盘
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!

Setting session cookie parameters in PHP can be achieved through the session_set_cookie_params() function. 1) Use this function to set parameters, such as expiration time, path, domain name, security flag, etc.; 2) Call session_start() to make the parameters take effect; 3) Dynamically adjust parameters according to needs, such as user login status; 4) Pay attention to setting secure and httponly flags to improve security.

The main purpose of using sessions in PHP is to maintain the status of the user between different pages. 1) The session is started through the session_start() function, creating a unique session ID and storing it in the user cookie. 2) Session data is saved on the server, allowing data to be passed between different requests, such as login status and shopping cart content.

How to share a session between subdomains? Implemented by setting session cookies for common domain names. 1. Set the domain of the session cookie to .example.com on the server side. 2. Choose the appropriate session storage method, such as memory, database or distributed cache. 3. Pass the session ID through cookies, and the server retrieves and updates the session data based on the ID.

HTTPS significantly improves the security of sessions by encrypting data transmission, preventing man-in-the-middle attacks and providing authentication. 1) Encrypted data transmission: HTTPS uses SSL/TLS protocol to encrypt data to ensure that the data is not stolen or tampered during transmission. 2) Prevent man-in-the-middle attacks: Through the SSL/TLS handshake process, the client verifies the server certificate to ensure the connection legitimacy. 3) Provide authentication: HTTPS ensures that the connection is a legitimate server and protects data integrity and confidentiality.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!

Atom editor mac version download
The most popular open source editor