Good day to you all,
here i'm working on a function that read a directory, for each folder show its images.
Here's the part that don't work :
No error but don't sort while it list files it should also sort them , Portrait, Landscape, Panoramic.
Here is my code :
PHP Code:
<?php
set_time_limit(0);
$directory = $_GET['dir'];
// Function that read a directory list of folder and result them function getDirectory( $path = '.', $level = 0 ){
$ignore = array( 'cgi-bin', '.', '..' ); // Directories to ignore when listing output. Many hosts // will deny PHP access to the cgi-bin.
$dh = @opendir( $path ); // Open the directory to the handle $dh
while( false !== ( $file = readdir( $dh ) ) ){ // Loop through the directory
if( !in_array( $file, $ignore ) ){ // Check that this file is not to be ignored
$spaces = str_repeat( ' ', ( $level * 4 ) ); // Just to add spacing to the list, to better // show the directory tree.
if( is_dir( "$path/$file" ) ){ // Its a directory, so we need to keep reading down...
//Creating var for Portrait images list $portrait = ""; //Creating var for Landscape images list $landscape = ""; //Creating var for panoramic images list $panoramic = ""; //Read that directory $files = scandir($path."/".$file); // Echo the name echo "<div id=\"bar\"><b>".$file."</b></div><br/>"; echo "<div>";
//For each file in tha folder foreach($files as $key => $value){
if ($value != "." && $value != "..") {
//Substring to $value his last 5 char $formatfind = substr($value,-5); // Subtracting to this the last 4 $format = substr($formatfind,0,-4); //This is in my naming convension.Portrait equal 1 landscape equal 0 and panoramic equal 2