php -- 目录、路径、磁盘

PHP文件与路径操作

----- 028-dir.php -----

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta http-equiv="content-type" content="text/html; charset=utf-8">
 5     <title>文件夹</title>
 6 </head>
 7 <body>
 8 <h2>文件夹</h2>
 9 <pre>
10 <?php
11     $dir_name = "D:/a";
12     $dir = opendir("D:/a");
13     echo "D:/a下:\n";
14     while($file = readdir($dir))
15     {
16         if(is_file($dir_name."/".$file))
17             echo "文件:";
18         else
19             echo "文件夹:";
20         echo iconv("gbk", "utf-8", $file), "\n";
21     }
22     var_dump(scandir("D:/a"));//数组形式返回文件夹下的文件
23     closedir($dir);
24 
25 ?>
26 </pre>
27 </body>
28 </html>

----- 029-path.php -----

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta http-equiv="content-type" content="text/html; charset=utf-8">
 5     <title>路径</title>
 6 </head>
 7 <body>
 8 <h2>路径</h2>
 9 <pre style="font-size: 16pt">
10 <?php
11     $file_name = "D:/a/php/root/028-dir.php";
12     echo "文件名部分:", basename($file_name), "\n";
13     echo "目录部分:", dirname($file_name), "\n";
14     echo "000.jpg的绝对路径:", realpath("000.jpg"), "\n";
15     echo "路径各个部分:\n";
16     var_export(pathinfo($file_name));
17 
18     $dir_name = "D:/a/php/root";
19     echo "\n\n磁盘可用空间:", round(disk_free_space($dir_name)/1073741828, 2), " GB\n";
20     echo "磁盘总空间:", round(disk_total_space($dir_name)/1073741828, 2), " GB\n";
21     echo "D:/a/res/txt/zzz.txt的大小:", round(filesize("D:/a/res/txt/zzz.txt")/1024, 2), "KB\n";
22 ?>
23 </pre>
24 </body>
25 </html>

转载于:https://www.cnblogs.com/baijifeilong/p/3750479.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值