Php file operations (2)

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.