I have a class that loops through a directory (5 images) and converts each image to base64 format and fills an array. However, it seems that the foreach loop only loops through once. There is 5 images in the directory, so it should have 5 iterations and the array should be 5 different images as well.
PHP
require_once "Results.php";
require_once "ImageHelper.php";
class IntroImageHelper {
public static function GetImages()
{
$results = new Results();
$results->IntroImages = Array();
$dir = new DirectoryIterator("img/");
$ImageExists = false;
foreach($dir as $file)
{
if($file->isFile())
{
$ImageExists = $file->__toString();
break;
}
}
if($ImageExists)
{
$tempImage = new Results();
$tempImage->ImageName = $ImageExists;
$tempImage->ImageData = ImageHelperIntroSlides::DownloadImage($file);
array_push($results->IntroImages, $tempImage);
}
return $results;
}
}
Output:
{"IntroImages: [
{"ImageName": "image.png",
"ImageDate": "base64imagedata"
}
]
}
array_push()inside the loop.