Created
August 24, 2022 17:37
-
-
Save relliv/5226c2fb80a98bae44f1c8c63771b748 to your computer and use it in GitHub Desktop.
List images with pure PHP and natsort
This file contains hidden or 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
$models3dPath = __DIR__ . '/./img/3d-models'; | |
$models3dList = null; | |
if (!file_exists($models3dPath)) { | |
mkdir($models3dPath, 0775, true); | |
} | |
if (file_exists($models3dPath)) { | |
$files = scandir($models3dPath); | |
$files = array_diff($files, array('.', '..')); | |
if (count($files)) { | |
$models3dList = array_map(function ($file) { | |
// get full file name | |
$fileName = explode('/', $file)[0]; | |
preg_match('/^[0-9]+-(.*)/', $fileName, $matches); | |
if (count($matches)) { | |
return $fileName; | |
} | |
}, $files); | |
} | |
} | |
$models3dList = array_filter(array_filter($models3dList), 'strlen'); | |
natsort($models3dList); | |
$models3dListHtml = implode('', array_map(function ($item) { | |
return "<div class=\"gallery-cell work-item hover-trigger hover-3\"> | |
<div class=\"work-container\"> | |
<div class=\"work-img\"> | |
<a href=\"img/site-3d-modelleri/{$item}\" class=\"lightbox-img\" title=\"Lonely Forest\"> | |
<img src=\"img/site-3d-modelleri/{$item}\" alt=\"\"> | |
<div class=\"hover-overlay\" data-overlay=\"1\"></div> | |
</a> | |
</div> | |
</div> | |
</div>"; | |
}, $models3dList)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment