list by date

Hi =)

I am using this code to list files in a directory


<?php $dir = dir("upload"); while (($file = $dir->read()) !== false) { if($file[0]!='.') echo 'Video name: ' . $file . '
'; } $dir->close(); ?>


now is there any way to edit this so that it would list files by the date uploaded so that the latest ends up in the top of the list?

I believe the DIR function will return the results based upon the system. So I don’t think you can change that through the script.

That being said, an alternative would be to use the shell_exec and then parse the results. Using the shell_exec you could pass the system dependent directory command (i.e. dir for windows, ls for *nix) and the appropriate “Sort” command (i.e. ls -lrt) to achieve the desired results.

If you want to get more complicated, I believe there is also a function that will allow you to “View” the file properties (including date accessed/created). You could then just put the results of the dir function in an array, chug back through and check the file creation date, and the kick out your results accordingly. I believe that function would be filectime. It might also be helpful to look through the other File manipulation Functions

thank you very much for your answer =)
I will take some day and try understand this =)

Sponsor our Newsletter | Privacy Policy | Terms of Service