Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Created February 22, 2014 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save james2doyle/9157605 to your computer and use it in GitHub Desktop.
Save james2doyle/9157605 to your computer and use it in GitHub Desktop.
list a folder of images and store the values in an array
<?php
$images = array();
if ($handle = opendir('uploads')) {
while (false !== ($entry = readdir($handle))) {
$check = preg_match("/\.(jpg|jpeg|png|gif|webp)/i", $entry);
if ($entry != "." && $entry != ".." && $check) {
$alt = preg_replace('/\.(jpg|jpeg|png|gif|webp)/', '', $entry);
$image_info = getimagesize('uploads/'.$entry);
$images[] = array(
'src' => 'uploads/'.$entry,
'filename' => $entry,
'width' => $image_info[0],
'height' => $image_info[1],
'title' => $alt,
'alt' => $alt
);
}
}
closedir($handle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment