Created
February 3, 2019 16:16
-
-
Save relliv/71ecc55f8de05cdcf5230f50faa40ad4 to your computer and use it in GitHub Desktop.
List of Files in Folder (PHP)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// folder path and | |
// limits of selected files, *.* = all files | |
$folder = 'upload/profiles/2018-11/*.*'; | |
// searched extensions | |
$ext_array = ['gif','jpg','jpeg','png']; | |
// get all files | |
$files = glob($folder); | |
// if there is any file | |
if ($files && is_array($files)){ | |
// loop in $files | |
foreach ($files as $file){ | |
// get file ext | |
$file_ext = pathinfo($file, PATHINFO_EXTENSION); | |
// if tehre is valid ext and searhed ext | |
if ($file_ext && in_array($file_ext, $ext_array)){ | |
echo "<img src=\"{$file}\">"; | |
} | |
} | |
} else { | |
echo 'there is no file'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment