I want to get picture from few sub-folder in a directory and i want to sort them as data. with the Following code I got the images now i want to sort them as data.
Note
every image name starts with the date and time of uploading example :-
default image name = "image.jpg"
after upload image name = "24-02-2016-09-42-33-image.jpg"
<?php
$dir = 'dist/userdata/'.$username.'/photos/';
if ($opendir = opendir ($dir) ) {
$files = 0;
while (($file = readdir ($opendir)) !== false && $files <= 2 + 1 ) {
if ($file !="." && $file !="..") {
$newdir = $dir.''.$file.'/';
if ($newopendir = opendir ($newdir)) {
$imgs = 0;
while (($img = readdir ($newopendir)) !== false && $imgs <= 3 + 1) {
if ($img !=="." && $img !=="..") {
$supported_files = array(
'jpeg',
'jpg',
'png'
);
$ext = strtolower(pathinfo($img, PATHINFO_EXTENSION));
if (in_array($ext, $supported_files)) {
echo '<img src="'.$newdir.''.$img.'"/>';
} else {
}
}
$imgs++;
}
}
}
$files++;
}
}
?>