2016-10-05 07:19:53 +00:00
|
|
|
<?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 //
|
2016-10-05 08:47:05 +00:00
|
|
|
else if( preg_match("/\.(jpg|jpeg|png)$/", $fname) )
|
2016-10-05 07:19:53 +00:00
|
|
|
$fetched[] = $fname;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (3) Returning result */
|
|
|
|
return $fetched;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-10-05 08:49:25 +00:00
|
|
|
// TRANSFORME UN ARBRE EN LISTE
|
|
|
|
function toFlaggedImage($folder, $name){
|
|
|
|
$flagged = [];
|
|
|
|
|
|
|
|
foreach($folder as $e=>$element)
|
|
|
|
if( !is_array($element) )
|
2016-10-05 10:13:48 +00:00
|
|
|
$flagged[] = substr("$name:$element", 1);
|
2016-10-05 08:49:25 +00:00
|
|
|
else
|
2016-10-05 10:13:48 +00:00
|
|
|
$flagged = array_merge($flagged, toFlaggedImage($element, "$name:$e") );
|
2016-10-05 07:19:53 +00:00
|
|
|
|
2016-10-05 08:49:25 +00:00
|
|
|
return $flagged;
|
|
|
|
}
|
2016-10-05 07:19:53 +00:00
|
|
|
|
|
|
|
/* [2] On affiche le résultat
|
|
|
|
=========================================================*/
|
2016-10-05 08:49:25 +00:00
|
|
|
$fetched = toFlaggedImage( getImages( $dir ) );
|
|
|
|
|
2016-10-05 07:19:53 +00:00
|
|
|
|
|
|
|
header('Content-Type: application/json');
|
2016-10-05 08:49:25 +00:00
|
|
|
echo json_encode( $fetched );
|