PHP folder operations

Source: Internet
Author: User
Tags glob

Files: Files + Directories

Determine the file type:

filetype ("path");    // returns a string Is_dir ("path");    // If the directory returns true to    determine whether the file is directory is_file("path");    // contrary to Dir to    determine whether the file is not a file

File properties:

Fileatime ("path");         // get file last access time Filectime ("path");         // Get file creation time Filemtime ("path");        // Get the file modification time filesize ("path");        // Get File Size file_exists ("path");        // To see if a file exists

/: (Root)

Root in Web page: representative www directory

Root in PHP: represents the disk directory

$_server [' Document_root '];    // gets the root www of the current server basename ("path");        // gets the file name in the path basename ("Path", "File type");    // gets the file name with the suffix removed dirname ("path");        // gets the part of the path that removes the file name PathInfo ("path");        // can get the file information returned is an array Realpath ("path");        // Convert A relative path to an absolute path (starting at the top-level directory)

Traverse Directory

Var_dump (glob// returns all files in the directory $attrglob("./touxiang/*"); foreach ($attras$v) {    echo$v. <br> ";}

Get the number of all files (including folders) under a folder
This method is used to get the number of files under the specified folder

$fname= "./0904";$dir=Opendir($fname);//open a directory to return to the directory resource while($url=Readdir($dir)){    Echo $fname." /".$url." <br> ";}Closedir($dir);//Close Directory Resourceget the size of all files in a directoryfunctionFsize ($fname){    $size= 0; $dir=Opendir($fname); //traverse directories, find files, accumulate size     while($u=Readdir($dir))    {        if($u=="." ||$u=="..")        {        }        Else        {            $zfname=$fname." /".$u; if(Is_file($zfname))            {                $size+=filesize($zfname); }        }    }        //find subdirectories, get the file size under subdirectories    Rewinddir($dir);  while($u=Readdir($dir))    {        if($u=="." ||$u=="..")        {        }        Else        {            $zfname=$fname." /".$u; if(Is_dir($zfname))            {                $size+ = Fsize ($zfname); }        }    }        Closedir($dir); return $size;}EchoFsize ("./0904");

PHP folder 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.