HTML Help

Go Back   HTML Help Central > Site Building Central > PHP

PHP PHP programming, learning PHP, PHP Help, etc. (PHP = Hypertext Preprocessor.)

Register Now for FREE!
Join HTML Help Central. To sign up for your FREE account INSTANTLY fill out the form below!

Username: Password: Confirm Password: E-Mail: Confirm E-Mail:
 
Image Verification
Please enter the six letters or digits that appear in the image opposite.

  I agree to forum rules 

» Online Users: 52
1 members and 51 guests
peaslee68
» HHC Sponsors
Closed Thread
 
Thread Tools Display Modes
  #1  
Old 12-19-2007, 06:14 AM
OffCourse OffCourse is offline
New Member
 
Join Date: Dec 2007
Posts: 1
PHP Dir Sorting

Hi

I have the following piece of code, which is then used by a flash application to display the pictures in a directory and make a slideshow.

How can I sort the files in the directory based on, let's say, filename?

PHP Code:
<images>
<?php
$dir 
"slideshow/";

if (
is_dir($dir)) {

    if (
$dh opendir($dir)) {
    
        while ((
$file readdir($dh)) !== false) {

            
$filetype substr($file,-3);
            
$filetype strtolower($filetype);
                        
            if (
$filetype == "jpg" || $filetype == "gif") { ?>
    <pic>
        <image>slideshow/<?php echo $file;?></image>
        <caption><?php echo $file;?></caption>
    </pic>
<?php            
            
}
        }
        
closedir($dh);
    }
}
?>
</images>
Thanks for the help.
  #2  
Old 12-19-2007, 02:12 PM
element's Avatar
element element is offline
Super Moderator
 
Join Date: Aug 2001
Location: New Jersey, USA
Posts: 2,118
Instead of looping through and displaying the files, loop through and add each file an array(), and then simply use the sort() function.

Once the array is sorted, just loop through the array and display the results.

If the process seems unclear I can post an example.
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching and Sorting? SkorpioLT HTML 1 07-19-2007 05:50 PM
PHP opendir sorting?? vtecin Server-Side Stuff 8 07-13-2007 11:00 AM
Sorting a multi-dimensional array in PHP... Billy41684 Server-Side Stuff 1 04-03-2006 01:06 PM

Powered by vBadvanced CMPS v3.2.0
All times are GMT -4. The time now is 03:51 AM.