PHP gets the name or path of all the files in the folder including the subdirectory files, _php tutorial

Source: Internet
Author: User

PHP gets the name or path of all the files in the folder including the subdirectory files.


/** New GetFile ($_dir[,$_emptydir,$_filetype]); * @parma $_dir is the directory name * @parma $_emptydir whether to get an empty folder, optional, default not get, true to get empty folder * @parma $_filetype Gets the file name type, optional, gets only the file name by default, True gets the file name with the path **/classGetFiles {Private $_dir; Private $_emptydir; Private $_filetype;  Public $_files;  Public function__construct ($_dir,$_emptydir=false,$_filetype=false) {        $this->_dir =$_dir; $this->_emptydir =$_emptydir; $this->_filetype =$_filetype; if($this-_emptydir) {            $this->getfileempty ($this->_dir,$this-_files); } Else {            $this->getfile ($this->_dir,$this-_files); }    }    //Read folder All files do not include empty folders    Private functionGetFile ($_dir,&$_arr) {        if(!!$_dirs=Opendir($_dir)) {             while(($_file=Readdir($_dirs)) !=false) {                if($_file== '.' ||$_file== '..')Continue; $_files=$_dir.' /'.$_file; if(Is_dir($_files)) {                    $this->getfile ($_files,$_arr); } Else {                    if($this-_filetype) {                        $_arr[] =$_files; } Else {                        $_arr[] =$_file; }                }            }        }        Closedir($_dirs); }    //read folder All files including empty folders    Private functionGetfileempty ($_dir,&$_arr) {        if(!!$_dirs=Opendir($_dir)) {             while(($_file=Readdir($_dirs)) !=false) {                if($_file== '.' ||$_file== '..')Continue; $_files=$_dir.' /'.$_file; if(Is_dir($_files) &&$this->isempty ($_files)) {                    $this->getfileempty ($_files,$_arr); } Else {                    if($this-_filetype) {                        $_arr[] =$_files; } Else {                        $_arr[] =$_file; }                }            }        }        Closedir($_dirs); }    //determine if the folder is empty    Private functionIsEmpty ($_dir) {        if(!!$_dirs=Opendir($_dir)) {             while(($_file=Readdir($_dirs)) !=false) {                if($_file! = '. ' &&$_file!= '..') {                    Closedir($_dirs); return true;  Break; }            }            Closedir($_dirs); return false; }    }}

Reprint Please specify source: http://www.ly89.cn/detailB/36.html

http://www.bkjia.com/PHPjc/1056841.html www.bkjia.com true http://www.bkjia.com/PHPjc/1056841.html techarticle PHP gets all files within the folder including the name or path of the subdirectory file,/* * New GetFile ($_dir[,$_emptydir,$_filetype]); * @parma $_dir is the directory name * @parma $_emptydir Are you receiving ... ?

  • 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.