PHP iterates through all the file functions in the specified directory and can specify the file type

Source: Internet
Author: User
This thanScandir out of the good
    1. /**
    2. * Traversal of files of the specified type under Get directory
    3. * @param $path
    4. * @param array $files
    5. * @return Array
    6. */
    7. function GetFiles ($path, & $files = Array ())
    8. {
    9. if (!is_dir ($path)) return null;
    10. $handle = Opendir ($path);
    11. while (false!== ($file = Readdir ($handle))) {
    12. if ($file! = '. ' && $file! = ' ... ') {
    13. $path 2 = $path. '/' . $file;
    14. if (Is_dir ($path 2)) {
    15. GetFiles ($path 2, $files);
    16. } else {
    17. if (Preg_match ("/\." ( gif|jpeg|jpg|png|bmp) $/i ", $file)) {
    18. $files [] = $path 2;
    19. }
    20. }
    21. }
    22. }
    23. return $files;
    24. }
Copy Code
  • 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.