TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Seperate directory reading (http://www.talkphp.com/general/4173-seperate-directory-reading.html)

Peuplarchie 04-22-2009 12:39 AM

Seperate directory reading
 
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 :

PHP Code:



<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!

Salathe 04-22-2009 09:05 AM

With all of these threads about reading files from a directory, please start separating your code into specific tasks. For this particular thread:
  1. Gather list of images in the directory
  2. Iterate over that list ordering by orientation (landscape/portrait)
  3. Display that sorted list in your required format (JavaScript in this case)

To help you determine which images are landscape or portrait you could use the getimagesize function.


All times are GMT. The time now is 02:00 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0