Skip to content

Instantly share code, notes, and snippets.

@raihan-uddin
Forked from benedict-w/read_files_from_dir.php
Created February 24, 2020 03:59
Show Gist options
  • Save raihan-uddin/4cfe35d5c675354a0edfa87cbc52bdef to your computer and use it in GitHub Desktop.
Save raihan-uddin/4cfe35d5c675354a0edfa87cbc52bdef to your computer and use it in GitHub Desktop.
PHP script to read files from a DIR parsing through a filename regex to match extensions
<?php
$files = array();
$folder = '../images';
$extensions = 'png';
if (is_dir($folder)){
$dir = opendir($folder);
while ($file = readdir($dir)) {
if (preg_match("/^[^\.].+\.{$extensions}$/i", $file)) {
$files[] = $file;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment