1 <?php 2 3 //文件:文件和文件夹 4 5 //1.判断文件 6 //var_dump(filetype("./aa")); 7 //var_dump(is_dir("./aa")); 8 //echo date("Y-m-d H:i:s",fileatime("./aa.txt")); 9 //echo filesize("aa.txt");<br /> 10 //var_dump(file_exists("./aaa.txt")); 11 12 //2.文件路径 13 //根: / 14 //php里面/代表根(是磁盘目录) 15 //var_dump(file_exists("/wamp/www/11.php")); 16 //网页里面/代表根(是www目录) 17 18 //echo $_SERVER['DOCUMENT_ROOT']; 19 //echo basename("/wamp/www/11.php",".php"); 20 //echo dirname("/wamp/www/11.php"); 21 //var_dump(pathinfo("/wamp/www/11.php")); 22 //echo realpath("./aa.txt"); 23 24 //目录操作 25 //rmdir("./bb");//只能删除空文件夹 26 //rename("./cc","./aa/dd"); 27 //var_dump(glob("./fenye/*.php")); 28 29 /*$dir = opendir("./fenye"); 30 31 while($f = readdir($dir)) 32 { 33 echo $f."<br>"; 34 } 35 36 closedir($dir);*/ 37 38 //给一个文件夹,读取文件夹里面文件的数量 39 40 /*echo ShuLiang("./fenye"); 41 42 //给一个文件夹,返回该文件夹下所有文件的数量 43 function ShuLiang($filename) 44 { 45 $sum=0; 46 47 $dir = opendir($filename); 48 while($f = readdir($dir)) 49 { 50 if($f=="." || $f=="..") 51 { 52 } 53 else 54 { 55 $lujing = $filename."/".$f; 56 if(is_file($lujing)) 57 { 58 $sum++; 59 } 60 else 61 { 62 $sum = $sum+ShuLiang($lujing); 63 } 64 } 65 } 66 closedir($dir); 67 68 return $sum; 69 }*/ 70 71 72 //文件操作 73 //touch("./cc.docx"); 74 //copy("./cc.txt","./fenye/cc.txt") 75 //unlink("./cc.txt"); 76 77 //echo file_get_contents("http://www.baidu.com"); 78 //file_put_contents("./ceshi.php","hello"); 79 //readfile("http://www.baidu.com"); 80 //var_dump(file("http://www.baidu.com")); 81 82 //$f = fopen("./aa.txt","a"); 83 //fwrite($f,"world"); 84 //echo fgetc($f); 85 //echo fgets($f); 86 //echo fread($f,2); 87 88 //fclose($f); 89 90 //给一个文件夹,删除该文件夹 91 ShanChu("./zhanneixin"); 92 function ShanChu($filename) 93 { 94 if(is_dir($filename)) 95 { 96 $dir = opendir($filename); 97 98 while($f = readdir($dir)) 99 { 100 if($f=="."||$f=="..") 101 { 102 103 } 104 else 105 { 106 $fname = $filename."/".$f; 107 if(is_file($fname)) 108 { 109 unlink($fname); 110 } 111 else 112 { 113 ShanChu($fname); 114 } 115 } 116 } 117 118 closedir($dir); 119 rmdir($filename); 120 } 121 else 122 { 123 unlink($filename); 124 } 125 } 126 127 128 ?>