Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post

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

  • #2
    Regular Coder
    Join Date
    Sep 2006
    Location
    Vermont, USA
    Posts
    154
    Thanks
    0
    Thanked 6 Times in 6 Posts
    Give this a shot - notice the server path at the top - you'll need to change that as well as the default folder path. I've also left the output/display up to you.

    PHP Code:
    <?php
        $images            
    = array('landscape' => array(), 'portrait' => array());
        
    $images_root    '/home/account/public_html/images/';
        
    $directory        = isset($_GET['folder']) && is_dir($images_root.$_GET['folder']) && is_readable($images_root.$_GET['folder']) ? $_GET['folder'].'/' '';
        
    $image_types    = array('png''jpg''jpeg''gif');

        foreach(
    glob($images_root.$directory.'*.*') as $image) : 
            
    $extension strtolower(array_pop(explode('.'$image)));

            if(!
    is_readable($image) || !in_array($extension$image_types)) : 
                continue;
            endif;

            list(
    $width$height)    = getimagesize($image);
            
    $image_layout            $width <= $height 'portrait' 'landscape';
            
    $modified_time            filemtime($image);

            
    $images[$image_layout][$modified_time] = array(
                                                            
    'path'        => str_replace($images_root''$image), 
                                                            
    'height'    => $height
                                                            
    'width'        => $width,
                                                            
    'date'        => date('Y-m-d H:i:s'$modified_time)
                                                        );
        endforeach;

        
    krsort($images['landscape']);
        
    krsort($images['portrait']);

        echo 
    '<pre>';
        
    print_r($images);
        echo 
    '</pre>';
    ?>
    Last edited by syosoft; 05-17-2008 at 08:08 AM.
    Active PHP/MySQL application developer available for immediate work.
    syosoft.com mavieo.com - Remote Web Site Administration Suite - Reseller Ready

  • #3
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    Thanks, I have tied it and I get an error maybe you would say why :
    Parse error: parse error, unexpected T_BOOLEAN_AND in.....


    PHP Code:


        $images            
    = array('landscape' => array(), 'portrait' => array());
        
    $site_root        '/domains/p/pet.test.com/user/htdocs/';
        
    $directory        = isset($_GET['folder']) ? && is_dir($site_root.$_GET['folder']) && is_readable($site_root.$_GET['folder']) ? $_GET['folder'].'/' 'default/';
        
    $image_types    = array('png''jpg''jpeg''gif');

        foreach(
    glob($site_root.$directory.'*.*') as $image) : 
            
    $extension strtolower(array_pop(explode('.'$image)));

            if(!
    is_readable($image) || !in_array($extension$image_types)) : 
                continue;
            endif;

            list(
    $width)    = getimagesize($image);
            
    $image_layout    $width <= 199 'portrait' 'landscape';

            
    $images[$image_layout][filemtime($image)] = str_replace($site_root''$image);
        endforeach;

        
    krsort($images['landscape']);
        
    krsort($images['portrait']);

        echo 
    '<pre>';
        
    print_r($images);
        echo 
    '</pre>'

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Post the exact error message(including the line number) and either the entire file, or the line the error points to, and a few previous lines.

    Edit:
    Code:
    $directory        = isset($_GET['folder']) ? && is_dir($site_root.$_GET['folder']) && is_readable($site_root.$_GET['folder']) ? $_GET['folder'].'/' : 'default/';
    That is at least one error. You probably just want to remove the "?".


  •  

    Posting Permissions

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