Need help.... sorting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chuspy
Forum Newbie
Posts: 2
Joined: Sat Jun 07, 2008 1:14 pm

Need help.... sorting

Post by chuspy »

I am new in php, so I need help. I want to se tup quick gallery on my photo portfolio site, bu i am stuck with sorting. Script is up and running, but it sorts files by alphabetical order, and I want it to sort it by date uploaded on server. Since I am new I am not so shure what or how to do, so need help.
script is:

Before <head>

Code: Select all

 
<?php if(isset($_REQUEST['big_image']) and $_REQUEST['big_image']!=''){?>
<?php 
$image_title = strtolower($_REQUEST['big_image']);
$image_title = str_replace('_',' ',$image_title);
$image_title = str_replace('.jpg','',$image_title);
?>
<?php }?>
 
In head:

Code: Select all

 
<?php if(isset($_REQUEST['big_image']) and $_REQUEST['big_image']!=''){?>
<title><?php echo $image_title;?></title>
<?php } else {?>
<title>Quick Photo Gallery</title>
<?php }?>
 
and finally in the body:

Code: Select all

 
<?php if(isset($_REQUEST['big_image']) and $_REQUEST['big_image']!=''){?>
 
<h1 style="text-transform:capitalize;"><?php echo $image_title;?></h1>
 
<?php list($image_width, $image_height) = getimagesize($_REQUEST['big_image']); ?>
<div style="border:1px solid #EBEBEB; margin-right:10px; margin-bottom:10px; padding:5px; width:<?php echo$image_width;?>px; display:block; clear:both; text-align:center;"><img src="image.php?file=<?php echo $_REQUEST['big_image'];?>&width=500&height=375" alt="<?php echo $image_title;?>" title="<?php echo $image_title;?>"/></div>
 
<?php }?>
 
 
<?php
if(!function_exists('get_file_extension')){
    function get_file_extension($filename) { 
        $filename = strtolower($filename) ; 
        $exts = split("[/\\.]", $filename) ; 
        $n = count($exts)-1; 
        $exts = $exts[$n]; 
        return $exts; 
    } 
}
 
if ($handle = opendir('.')) {
    /* This is the correct way to loop over the directory. */
    while (false !== ($file = readdir($handle))) {
        if(get_file_extension(strtolower($file)) == 'jpg' and $file!= 'no_image.jpg'){
        
        $image_title = strtolower($file);
        $image_title = str_replace('_',' ',$image_title);
        $image_title = str_replace('.jpg','',$image_title);
        
            echo '<div style="border:1px solid #EBEBEB; margin-right:10px; margin-bottom:10px; padding:5px; width:auto; display:block; float:left;"><a href="'.$file.'"><img border="0" src="image.php?file='.$file.'&width=200&height=60" alt="'.$image_title.'" title="'.$image_title.'"/></a></div>';
        }
    }
    closedir($handle);
}
?> 
 
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Need help.... sorting

Post by pickle »

Make an array of all the files. Use array_multisort() to sort by something other than the key.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply