Created
June 27, 2017 14:19
-
-
Save 8lane/a3e8b068b1fa44bd2e3f6beb06ed4c13 to your computer and use it in GitHub Desktop.
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 | |
$limit = 4; | |
$order = "DESC"; | |
if(array_key_exists('limit',$_GET)) { | |
$limit = $_GET['limit']; | |
} | |
if(array_key_exists('order',$_GET)) { | |
$order = $_GET['order']; | |
} | |
if(array_key_exists('newer',$_GET)) { | |
$newer = $_GET['newer']; | |
} | |
$files = glob("../../../sec/images/*.*"); | |
try { | |
if(empty($files)) { | |
throw new Exception("no images"); | |
} | |
usort($files, function($a, $b) { | |
return filemtime($a) > filemtime($b); | |
}); | |
if (!array_key_exists($newer, $files)) { | |
$array = [["id" => null]]; | |
echo json_encode($array); | |
die(); | |
} else { | |
$filePathSplit = explode('/', $files[$newer]); | |
} | |
$imageName = array_values(array_slice($filePathSplit, -1))[0]; | |
$id = array_search($newer, array_keys($files)); | |
$imageNameSplit = explode('-', $imageName); | |
$firstName = $imageNameSplit[0]; | |
$timestamp = explode('.', $imageNameSplit[1])[0]; | |
$array = [ | |
[ | |
"id" => $id, | |
"first_name" => $firstName, | |
"last_name" => "", | |
"filename" => $imageName, | |
"timestamp" => (int)$timestamp, | |
] | |
]; | |
echo json_encode($array); | |
} catch(Exception $e) { | |
echo json_encode(['error' => $e->getMessage()]); | |
error_log($e->getMessage()); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment