www.webdeveloper.com
Results 1 to 3 of 3

Thread: Sort (date & size) listing of dir.

  1. #1
    Join Date
    Feb 2006
    Posts
    352

    Sort (date & size) listing of dir.

    Good day to you all,
    I'm building a little image directory viewer and I want it to list the images by date they were uploaded and within that by landscape or portrait.

    I would need newest on top.


    Here is the code I have so far :

    PHP Code:

    <?php

    $val
    $_GET['folder'];
    $val.="/";




    $imgdir $val// the directory, where your images are stored
    $allowed_types = array('png','jpg','jpeg','gif'); // list of filetypes you want to show

    $dimg opendir($imgdir);
    while(
    $imgfile readdir($dimg))
    {
     if(
    in_array(strtolower(substr($imgfile,-3)),$allowed_types))
     {
      
    $a_img[] = $imgfile;
      
    sort($a_img);
      
    reset ($a_img);
     } 
    }

    $totimg count($a_img); // total image number
     
    for($x=0$x $totimg$x++)
    {
     
    $size getimagesize($imgdir.'/'.$a_img[$x]);


     
    echo 
    "<tr><td>";
    if (
    $size[0] > "199"){

     echo 
    '<img src="'.$imgdir.'/'.$a_img[$x].'" width="50" border="0">';
    }
    echo 
    "</td</tr>";
     
     
    echo 
    "<tr><td>";
    if (
    $size[1] > "199"){

     echo 
    '<img src="'.$imgdir.'/'.$a_img[$x].'" width="50" border="0">';
    }
    echo 
    "</td></tr>";
    }
    ?>


    Can someone guide me with this please ?

    Thanks !
    Have a nice day !
    That's why we are not alone on earth, to help each other !
    Let's REbuild that for ourselves !

  2. #2
    Join Date
    Aug 2006
    Location
    Michigan
    Posts
    1,046
    if this is on a Linux box you could use a command like

    $results = `ls -ltr`;
    echo $results;

    might be best to give the full path like this
    $results = `/path/to/dir/ls -lrt`;

    these are backticks ` not single quotes '

  3. #3
    Join Date
    Feb 2006
    Posts
    352
    i'm on wind 2003, no db, php4
    That's why we are not alone on earth, to help each other !
    Let's REbuild that for ourselves !

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles