PHP Course---File operation and file Upload code summary

Source: Internet
Author: User
Tags php language

PHP file contains directories and files two kinds

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >PHP//Get file Type      filetype("./1.jpg");//Files: File      filetype("./code");//Catalog: dir//Judging file types      Is_file("./1.jpg");//Judging is not a file      Echo Is_dir("./code");//Judging is not a directory          Date("Y-m-d h:i:s",Fileatime("1.jpg"));//gets the last access time      Date("Y-m-d h:i:s",Filectime("1.jpg"));//when the file was created      Date("Y-m-d h:i:s",Filemtime("1.jpg"));//when the file was modified      filesize("1.jpg")/1024;//size of File      file_exists("2.jpg");//determine if a file exists          filetype("/wamp");//current path with./or do not write, parent path with: /;         /*forward slash/represents the root directory. If it is written in the PHP language/it represents the root of the disk, if it is used in the pages of the page/it represents the root of the server*/        Echo"; $_server[' Document_root '];//find the root directory of the site         basename("./code/db.inc.php", ". php");//returns the file name from the path     dirname("./code/db.inc.php");//returns the directory name from the path     Print_r(PathInfo("./code/db.inc.php"));//returns all information for the path, the return type is an array     Realpath("1.jpg");//To convert a relative path to an absolute path        /*Directory Operations*/     mkdir("./suiji");//Create folder (directory)         rmdir("./suiji");//Delete directory, only empty folders are deleted         Rename("./name", "./code/suiji");//move or rename a folder          Print_r(Glob("./code/*.php"));//get all files in this directory, you can filter/Open Directory resources     $dir=Opendir("./code"); //read the file, each reading a pointer down one, note the first one is. Represents the current directory, and the second is: Represents the previous level of the directory      while($filename=Readdir($dir))     {         Echo $filename." <br> "; }     Echo"***************************"; Rewinddir($dir);  while($filename=Readdir($dir))     {         Echo $filename." <br> "; }     //Close Resource     Closedir($dir); /*file Operations*/     Touch("./2.txt");//Create a file     Copy("source", "target");//Copying Files     unlink("./code/2.txt");//Deleting Files     file_get_contents("http://www.baidu.com");//Read File     file_put_contents("./2.txt", "Hello World");//writes the content, overwriting     ReadFile("http://www.baidu.com");//read file content direct output     $attr=file("./2.txt");//read the contents of the file, and then return an array of each row         $fp=fopen("./2.txt", "R");//open a file resource        fwrite($fp, "bbbbbbbbbbb");//Write Content         while(!feof($fp))//when read error or read to the end returns true    {        Echo fgetc($fp);//Read the contents, one character at a time, read the pointer down    }         while(!feof($fp))    {        Echo fgets($fp)." <br> ";//read the content, one line at a time    }        //Echo fread ($fp, 100);//read content, can control how many characters to read        fclose($fp); //file upload $_files array $_files["File"] ["Name"];//the name of the file being uploaded $_files["File"] ["type"];//the type of file being uploaded $_files["File"] ["Size"];//the size of the file being uploaded (in bytes) $_files["File"] ["Tmp_name"];//The name of the temporary copy of the file that is stored on the server $_files["File"] ["Error"];//error code caused by file upload?></body>

PHP Course---File operation and file upload code summary

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.