I have a api that returns requested images paths to front end. But in Linux server its needs natural sorting. I want to natural sort values in the yol
key.
$klein->respond('GET', '/getPaths/[:name]', function($request,$response) {
$path00 = "../manga/" . $request->name;
function getAll($path00)
{
$dirs = [];
foreach (new DirectoryIterator($path00) as $item) {
if (!$item->isDir() || $item->isDot()) {
continue;
}
$gedo = [];
$path01 = $path00 . "/" . $item;
$path02 = substr($path01, 3);
$yol = new DirectoryIterator($path01);
foreach ($yol as $esya) {
if (!$esya->isDot() && $esya->getFilename() !== ".DS_Store") {
$gedo[] = $path02 . "/" . $esya->getFilename();
}
}
$dirs[] = array('klasor' => $item->getFilename(), 'yol' => $gedo);
}
return $dirs; // Output its in the image.
};
$data = getAll($path00);
$response->json($data);
});
Output: