Page 1 of 1

Seperate directory reading

Posted: Tue Apr 21, 2009 7:38 pm
by Peuplarchie
Good day to you all,
I was wondering how to seperate the result of a direcory read.
Example, I know the files will be images.

How can I show the portrait first and then landscape second ?

here is my code :

Code: Select all

 
 
 
<html>
<head>
 
    <SCRIPT language="JavaScript">
    <!--
    if (document.images)
    {
      preload_image = new Image(25,25); 
<?PHP
//  directory name sent by url
$dir = $_GET['dir'];
$file = $_GET['file'];
 
//define the path as relative
$path = $dir."".$file;
 
//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");
 
echo "Directory Listing of $path<br/>";
 
//running the while loop
while ($file = readdir($dir_handle)) 
{
   if($file!="." && $file!="..")
    
      echo "preload_image.src=\"http://test.peuplies.info/PHP/Photos_gallery/".$path."/".$file.""; 
 
}
 
echo "} //-> </script> </head> <body><center>";
 
 
 
while ($file = readdir($dir_handle)) 
{
   if($file!="." && $file!="..")
    
      echo "<img src=\"".$path."/".$file."\" width=\"50px\">"; 
 
}
 
 
 
 
 
 
 
//closing the directory
closedir($dir_handle);
 
 
?>
 
 
 
</center>
 
</body>
</html>
 
 

Thanks!

Re: Seperate directory reading

Posted: Wed Apr 22, 2009 7:41 am
by miro_igov
Insert all images in multidimensional array instead of directly print them, use getimagesize() to find the width and height of every image and if width>height set isLandscape (which is a part of the array) to 1 , else set to 0. Then do an array sort, then loop through the array and echo "preload_image.src=\"http://test.peuplies.info/PHP/Photos_ga ... ."/".$file."";