PHP View all files in directory

Source: Internet
Author: User

[1]. [Code][PHP] Code jumps to [1]?
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 <?php/*** 遍历目录,结果存入数组。支持php4及以上。php5以后可用scandir()函数代替while循环。* @param string $dir* @return array*/function my_scandir($dir){    $files = array();    if ( $handle = opendir($dir) ) {        while ( ($file = readdir($handle)) !== false )         {            if ( $file != ".." && $file != "." )             {                if ( is_dir($dir . "/" . $file) )                 {                    $files[$file] = my_scandir($dir . "/" . $file);                }                else                {                    $files[] = $file;                }            }        }        closedir($handle);        return $files;    }}function my_scandir1($dir){    $files = array();    $dir_list = scandir($dir);    foreach($dir_list as $file)    {        if ( $file != ".." && $file != "." )         {            if ( is_dir($dir . "/" . $file) )             {                $files[$file] = my_scandir1($dir . "/" . $file);            }            else            {                $files[] = $file;            }        }    }        return $files;}$result = my_scandir(‘./‘);$result = my_scandir1(‘./‘);?>

PHP View all files in directory

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.