Listing all images in a directory using PHP

前端 未结 8 720
悲&欢浪女
悲&欢浪女 2021-01-04 08:39

I have the code below that lists all the images in a folder, the problem is that it finds some files ( a . and a ..) that I am not sure what they are so I a

相关标签:
8条回答
  • 2021-01-04 09:08

    Use glob function.

    <?php
    define('IMAGEPATH', 'images/');
    foreach(glob(IMAGEPATH.'*') as $filename){
        $imag[] =  basename($filename);
    }
    print_r($imag);
    ?>
    

    You got all images in array format

    0 讨论(0)
  • 2021-01-04 09:11

    I like PHP's glob function.

    foreach(glob(IMAGEPATH.'*') as $filename){
        echo basename($filename) . "\n";
    }
    
    0 讨论(0)
提交回复
热议问题