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

 <!DOCTYPE html>
 <html>
 <head>
     <meta http-equiv="content-type" content="text/html; charset=utf-8">
     <title>文件夹</title>
 </head>
 <body>
 <h2>文件夹</h2>
 <pre>
 <?php
     $dir_name = "D:/a";
     $dir = opendir("D:/a");
     echo "D:/a下:\n";
     while($file = readdir($dir))
     {
         if(is_file($dir_name."/".$file))
             echo "文件:";
         else
             echo "文件夹:";
         echo iconv("gbk", "utf-8", $file), "\n";
     }
     var_dump(scandir("D:/a"));//数组形式返回文件夹下的文件
     closedir($dir);

 ?>
 </pre>
 </body>
 </html>

php -- 目录、路径、磁盘-LMLPHP

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

 <!DOCTYPE html>
 <html>
 <head>
     <meta http-equiv="content-type" content="text/html; charset=utf-8">
     <title>路径</title>
 </head>
 <body>
 <h2>路径</h2>
 <pre style="font-size: 16pt">
 <?php
     $file_name = "D:/a/php/root/028-dir.php";
     echo "文件名部分:", basename($file_name), "\n";
     echo "目录部分:", dirname($file_name), "\n";
     echo "000.jpg的绝对路径:", realpath("000.jpg"), "\n";
     echo "路径各个部分:\n";
     var_export(pathinfo($file_name));

     $dir_name = "D:/a/php/root";
     echo "\n\n磁盘可用空间:", round(disk_free_space($dir_name)/1073741828, 2), " GB\n";
     echo "磁盘总空间:", round(disk_total_space($dir_name)/1073741828, 2), " GB\n";
     echo "D:/a/res/txt/zzz.txt的大小:", round(filesize("D:/a/res/txt/zzz.txt")/1024, 2), "KB\n";
 ?>
 </pre>
 </body>
 </html>

php -- 目录、路径、磁盘-LMLPHP

04-28 20:41
查看更多