A detailed introduction to PHP file Operations (i)

Source: Internet
Author: User
Determine file type

Var_dump (FileType ("./img")); Returns the file type, directory, or file Var_dump (Is_dir ("./img/11.png")); Determine if the given file is not a directory is_file (); Determine whether the given file is not a file

File properties

Var_dump (Date ("Y-m-d h:i:s", Fileatime ("./img/11.png")); File last 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 exists

File path

/on behalf of  the root Web page inside represents the WWW directory   PHP inside represents the disk root var_dump (file_exists ("/wamp/www/1220/wenjian/img/11.png"));//File Presence echo $_ server[' Document_root ']; Fetch the server root path echo basename ("/wamp/www/1220/wenjian/img/11.png"); Gets the file name in the path echo dirname ("/wamp/www/1220/wenjian/img/11.png"); Directory name Var_dump in the path (PathInfo ("/wamp/www/1220/wenjian/img/11.png")); Returns the array echo Realpath ("./img/11.png");//convert relative path to absolute path

Traverse Directory

Var_dump (Glob ("./ajax/*")); Returns an array of all files in this directory

Give me a folder that returns the number of files in that 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/*");

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.