PHP file Operation Base: directory operations, file operations

Source: Internet
Author: User

<!    DOCTYPE html>PHP// directory operation//mkdir ("./www");//Create Directory,//rmdir ("./www");//delete directory (directory must be empty to delete);//rename ("./img"); , "./phpmyadmin/img");//Move the file, the first one is the file that needs to be moved, the second is the position after the move//file overall operation//touch ("./11.txt");//Create File//copy ("./img/11.png", ". /tmp/11.png ");//Copy the file, the first one is the source file, the second one is copied to that place. Unlink ("./11.txt");//delete files. Echo file_get_contents ("http://www.baidu.com");//Read the contents of the file, either locally or remotely//echo file_put_contents ("./img/11.txt", " Hello World "); The original content overlay is overwritten by the new content//readfile ("./img/11.txt ");//Read the file and output//$attr = Files (". /www/wenjian.php ");//var_dump ($attr); Put each line of data in the file into the array//file contents operation//$fp = fopen ("./img/11.txt", "R"),//R read-only, r+ read and write, W write empty, w+ read and write, a writes to the end of the file, A + reads and writes, X creates and opens in writing; Add a B to represent operable binaries (recommended addition)//fwrite ($FP, "Ceshi");//write Content//echo fgetc ($fp);//Get the contents of the file (one character at a time to read, want to show more output several times). while (!feof ($FP))//feof (), this function is used to determine whether the pointer has reached the end of the file, if it has been pointed to the ends of the file, then the value of the feof ($fp) function is "true", that is, return a non-0 value; otherwise return 0;//{//echo fgets ($fp). "<br/>";//}//for example, output such as//echo fgets ($FP);//Read Only one line at a time,//echo fread ($FP, 10);//Read how long, length depends on the following variables. Fclose ($FP); ?></body>

The Feof function example shows a diagram:

PHP file Operation Base: directory operations, file operations

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.