67 lines
1.4 KiB
PHP
Executable File
67 lines
1.4 KiB
PHP
Executable File
<?php
|
|
|
|
|
|
/* [0] Initialization
|
|
=========================================================*/
|
|
/* (1) Catch 'pictures' dir */
|
|
$dir = dirname(__FILE__);
|
|
|
|
|
|
/* [2] Listing all pictures recursivly
|
|
=========================================================*/
|
|
function getImages($directory){
|
|
|
|
/* (1) We get the direct content of the dir */
|
|
$files = scandir($directory);
|
|
$fetched = [];
|
|
|
|
// if error
|
|
if( !is_array($files) ) return [];
|
|
|
|
|
|
/* (2) For each element in directory */
|
|
foreach( $files as $e=>$fname ){
|
|
|
|
// {0} Avoid . and .. //
|
|
if( in_array($fname, ['.', '..']) )
|
|
continue;
|
|
|
|
|
|
$element = "$directory/$fname";
|
|
|
|
// {1} If subdir (excepted . and ..)-> applying recursivly //
|
|
if( is_dir($element) )
|
|
$fetched[$fname] = getImages($element);
|
|
|
|
// {2} If not picture -> unset //
|
|
else if( preg_match("/\.(jpg|jpeg|png)$/", $fname) )
|
|
$fetched[] = $fname;
|
|
|
|
}
|
|
|
|
/* (3) Returning result */
|
|
return $fetched;
|
|
|
|
}
|
|
|
|
// TRANSFORME UN ARBRE EN LISTE
|
|
function toFlaggedImage($folder, $name){
|
|
$flagged = [];
|
|
|
|
foreach($folder as $e=>$element)
|
|
if( !is_array($element) )
|
|
$flagged[] = substr("$name/$element", 1);
|
|
else
|
|
$flagged = array_merge($flagged, toFlaggedImage($element, "$name/$e") );
|
|
|
|
return $flagged;
|
|
}
|
|
|
|
/* [2] On affiche le résultat
|
|
=========================================================*/
|
|
$fetched = toFlaggedImage( getImages( $dir ) );
|
|
|
|
|
|
header('Content-Type: application/json');
|
|
echo json_encode( $fetched );
|