Created
February 22, 2014 16:34
-
-
Save james2doyle/9157605 to your computer and use it in GitHub Desktop.
list a folder of images and store the values in an array
This file contains 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
<?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