Home > Article > Backend Development > Detailed introduction to PHP file operations (2)
Detailed introduction to PHP file operations (2)
//创建目录 mkdir("./aa"); //删除目录 目录必须为空才可以删除 rmdir("./img"); //移动目录文件 rename("./img","./ajax/img"); //创建文件 touch("./11.txt"); //复制文件 copy("./11.txt","./ajax/11.txt"); //删除文件 unlink("./11.txt"); //读取文件内容(本地,远程) echo file_get_contents("http://www.baidu.com"); //写入文件内容(覆盖) file_put_contents("./ajax/11.txt","hello world"); //读取文件并输出 readfile("./11.txt"); //将文件中每行数据放到数组 $arr = file("./ajax/test.php"); //打开文件资源 $fp = fopen("./11.txt","a"); //写入内容 fwrite($fp,"ceshi"); //一次读一行 echo fgets($fp); //读多行 echo fread($fp,2); //关闭文件资源 fclose($fp); //删除一个文件夹 /*$fname = "./ajax"; $d = opendir($fname); while($url = readdir($d)) { echo $fname."/".$url."<br>"; } closedir($d);*/ //rmdir() //给我一个文件夹,删掉 function Del($url) { //清空 $d = opendir($url); while($u = readdir($d)) { if($u!="." && $u != "..") { $fname = $url."/".$u; if(is_file($fname)) { unlink($fname); } else { Del($fname); } } } closedir($d); //删除 rmdir($url); } Del("./ajax");
The above is the detailed content of Detailed introduction to PHP file operations (2). For more information, please follow other related articles on the PHP Chinese website!