This article introduces php file operations in detail (2). If you need it, refer
Php file operations (2)
// Create the directory mkdir (". /aa "); // The directory to be deleted must be empty before rmdir (". /img "); // Move the directory file rename (". /img ",". /ajax/img "); // create a file touch (". /11.txt"); // copy the file copy (". /11.txt ",". /ajax/11.txt"); // delete the file unlink (". /11.txt"); // read the file content (local, remote) echo file_get_contents ("http://www.baidu.com"); // write the file content (overwrite) file_put_contents (". /ajax/11.txt", "hello world"); // read the file and output readfile (". /11.txt"); // Put each row of data in the file into the array $ arr = file (". /ajax/test. php "); // open the file resource $ fp = fopen (". /11.txt", "a"); // write content fwrite ($ fp, "ceshi"); // read a row echo fgets ($ fp) at a time ); // read multi-row echo fread ($ fp, 2); // close the file resource fclose ($ fp); // delete a folder/* $ fname = ". /ajax "; $ d = opendir ($ fname); while ($ url = readdir ($ d) {echo $ fname. "/". $ url."
";} Closedir ($ d); * // rmdir () // give me a folder and delete function Del ($ url) {// clear $ d = opendir ($ url); while ($ u = readdir ($ d) {if ($ u! = "." & $ U! = ".. ") {$ Fname = $ url. "/". $ u; if (is_file ($ fname) {unlink ($ fname) ;}else {Del ($ fname) ;}} closedir ($ d ); // delete rmdir ($ url);} Del (". /ajax ");
The above is a detailed description of PHP file operations (2). For more information, see other related articles in the first PHP community!