Created
June 27, 2017 12:55
-
-
Save 8lane/df8fbaad010f71ed4698e0c4a12fa964 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)) { | |
// $filePathSplit = explode('/', array_values(array_slice($files, -1))[0]); | |
//} else { | |
$filePathSplit = explode('/', $files[$newer]); | |
} | |
$imageName = array_values(array_slice($filePathSplit, -1))[0]; | |
$imageNameSplit = explode('-', $imageName); | |
$firstName = $imageNameSplit[0]; | |
$timestamp = explode('.', $imageNameSplit[1])[0]; | |
$array = [ | |
[ | |
"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