Php file operations (1)

Source: Internet
Author: User
Tags glob
This article describes php file operations in detail (1). If you need it, you can refer to the following section to determine the file type.

Var_dump (filetype (". /img "); // return the file type, directory or file var_dump (is_dir (". /img/11.png"); // checks whether the given file is a directory is_file (); // checks whether the given file is a file.

File attributes

Var_dump (date ("Y-m-d H: I: s", fileatime (". /img/11.png"); // last file access time var_dump (date ("Y-m-d H: I: s", filemtime (". /img/11.png"); // file modification time echo filesize (". /img/11.png"); // file size filectime ("") // file creation time file_exists ("") // File existence

File path

/Indicates that the root page represents the www Directory. php indicates the disk root var_dump (file_exists ("/wamp/www/1220/wenjian/img/11.png ")); // whether the file contains echo $ _ SERVER ['document _ root']; // Obtain the server root path echo basename ("/wamp/www/1220/wenjian/img/11.png "); // Obtain the file name echo dirname ("/wamp/www/1220/wenjian/img/11.png") in the path "); // directory name var_dump (pathinfo ("/wamp/www/1220/wenjian/img/11.png") in the path; // returns the array echo realpath (". /img/11.png"); // converts relative paths to absolute paths.

Traverse directories

Var_dump (glob ("./ajax/*"); // returns an array of all files in the directory.

Give me a folder and return the number of all files in the folder

function ShuLiang($url){   $sl = 0;      $arr = glob($url);   foreach($arr as $v)   {      if(is_file($v))      {         $sl++;      }      else      {         $sl += ShuLiang($v."/*");      }   }         return $sl;}echo ShuLiang("./ajax/*");

The above is a detailed description of PHP file operations (1). 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.