<?php
//文件:文件和文件夹
//1.判断文件
//var_dump(filetype("./aa"));
//var_dump(is_dir("./aa"));
//echo date("Y-m-d H:i:s",fileatime("./aa.txt"));
//echo filesize("aa.txt");<br />
//var_dump(file_exists("./aaa.txt"));
//2.文件路径
//根: /
//php里面/代表根(是磁盘目录)
//var_dump(file_exists("/wamp/www/11.php"));
//网页里面/代表根(是www目录)
//echo $_SERVER['DOCUMENT_ROOT'];
//echo basename("/wamp/www/11.php",".php");
//echo dirname("/wamp/www/11.php");
//var_dump(pathinfo("/wamp/www/11.php"));
//echo realpath("./aa.txt");
//目录操作
//rmdir("./bb");//只能删除空文件夹
//rename("./cc","./aa/dd");
//var_dump(glob("./fenye/*.php"));
/*$dir = opendir("./fenye");
while($f = readdir($dir))
{
echo $f."<br>";
}
closedir($dir);*/
//给一个文件夹,读取文件夹里面文件的数量
/*echo ShuLiang("./fenye");
//给一个文件夹,返回该文件夹下所有文件的数量
function ShuLiang($filename)
{
$sum=0;
$dir = opendir($filename);
while($f = readdir($dir))
{
if($f=="." || $f=="..")
{
}
else
{
$lujing = $filename."/".$f;
if(is_file($lujing))
{
$sum++;
}
else
{
$sum = $sum+ShuLiang($lujing);
}
}
}
closedir($dir);
return $sum;
}*/
//文件操作
//touch("./cc.docx");
//copy("./cc.txt","./fenye/cc.txt")
//unlink("./cc.txt");
//echo file_get_contents("http://www.baidu.com");
//file_put_contents("./ceshi.php","hello");
//readfile("http://www.baidu.com");
//var_dump(file("http://www.baidu.com"));
//$f = fopen("./aa.txt","a");
//fwrite($f,"world");
//echo fgetc($f);
//echo fgets($f);
//echo fread($f,2);
//fclose($f); //文件打开必须关闭,否则无法进行很多操作
//给一个文件夹,删除该文件夹
:
ShanChu("./zhanneixin"); function ShanChu($filename) { if(is_dir($filename)) { $dir = opendir($filename); while($f = readdir($dir)) { if($f=="."||$f=="..") { } else { $fname = $filename."/".$f; if(is_file($fname)) { unlink($fname); } else { ShanChu($fname); } } } closedir($dir); rmdir($filename); } else { unlink($filename); } }