PHP 文件管理下
<?php
//文件整体操作
//touch("./11.txt"); //创建文件
//unlink("./11.txt"); //删除文件
//copy("./touxiang/11.jpg","./22.jpg"); //复制文件
//echo file_get_contents("./ceshi.txt"); //读取文件内容
//echo file_get_contents("http://www.baidu.com"); //读取远程文件
//file_put_contents("./ceshi.txt","hello world"); //写入内容
//readfile("http://www.baidu.com"); //读文件并输出
//$arr = file("http://www.baidu.com"); //读文件返回行的数组
//var_dump($arr);
//文件的部分操作
//$f = fopen("./ceshi.txt","r"); //打开文件
//echo fgetc($f); //一个字符一个字符读
//echo fgets($f); //一次读一行
//echo fread($f,5); //读指定长度的字符
//fwrite($f,"\r\nceshi aaaa"); //写入内容
//fclose($f); //关闭文件
//删除文件夹
//给我一个文件夹,先删掉里面的所有文件,再删除该文件夹
function delDir($fname){
if(is_dir($fname)){
$d = opendir($fname);
while($name = readdir($d)){
if($name!="." && $name!=".."){
$wzpath = $fname."/".$name;
if(is_file($wzpath)){
unlink($wzpath);
}else{
delDir($wzpath);
}
}
}
closedir($d);
rmdir($fname);
}else{
unlink($fname);
}
}
delDir("./aa");