Skip to content

Instantly share code, notes, and snippets.

@benedict-w
Last active February 24, 2020 04:31
Show Gist options
  • Save benedict-w/3979607 to your computer and use it in GitHub Desktop.
Save benedict-w/3979607 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