Skip to content

Instantly share code, notes, and snippets.

@relliv
Created February 3, 2019 16:16
Show Gist options
  • Save relliv/71ecc55f8de05cdcf5230f50faa40ad4 to your computer and use it in GitHub Desktop.
Save relliv/71ecc55f8de05cdcf5230f50faa40ad4 to your computer and use it in GitHub Desktop.
List of Files in Folder (PHP)
// 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