Gestion du listing des pictures [public_html/pictures/index.php]

This commit is contained in:
xdrm-brackets 2016-10-05 09:19:53 +02:00
parent c8530d100b
commit 0ffc6fb30c
8 changed files with 57 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 558 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

57
public_html/pictures/index.php Executable file
View File

@ -0,0 +1,57 @@
<?php
/* [0] Initialization
=========================================================*/
/* (1) Catch 'pictures' dir */
$dir = dirname(__FILE__);
/* (2) Defining authorized extensions */
$ext = ['jpg', 'png', 'jpeg'];
$checker = '/\.('. implode('|', $ext) .')$/i';
/* [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($checker, $fname) )
$fetched[] = $fname;
}
/* (3) Returning result */
return $fetched;
}
/* [2] On affiche le résultat
=========================================================*/
header('Content-Type: application/json');
echo json_encode( getImages($dir) );

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB