mirror of
https://github.com/php/web-php.git
synced 2026-03-23 23:02:13 +01:00
Fix counting logic.. as we skip an item if it doesn't exist
Also, don't allow more then 50 pics
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
|
||||
// determine how many images to serve.
|
||||
if (isset($_REQUEST['count'])) {
|
||||
$count = intval($_REQUEST['count']);
|
||||
$count = min(intval($_REQUEST['count']), 50);
|
||||
} else {
|
||||
header('HTTP/1.1 400', true, 400);
|
||||
print json_encode(array(
|
||||
@@ -46,10 +46,11 @@ if (!$photos || !is_array($photos)) {
|
||||
// prepare requested number of elephpants at random.
|
||||
shuffle($photos);
|
||||
$elephpants = array();
|
||||
foreach ($photos as $n => $photo) {
|
||||
$got = 0;
|
||||
foreach ($photos as $photo) {
|
||||
|
||||
// stop when we have the requested number of photos.
|
||||
if ($n == $count || $n > 20) {
|
||||
if ($got == $count) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -58,6 +59,7 @@ foreach ($photos as $n => $photo) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$got++;
|
||||
// add photo to response array.
|
||||
$elephpants[] = array(
|
||||
'title' => $photo['title'],
|
||||
@@ -67,3 +69,4 @@ foreach ($photos as $n => $photo) {
|
||||
}
|
||||
|
||||
print json_encode($elephpants);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user