displaying files in name order or in number order

hi im trying to display a load of images via the name alphabetically and it just doesnt work any ideas or even in number increments such as 1 2 3 4 5… and so on but it just doesnt do it here is my code any idea

<?php $dir = "img/thumbs"; //open directory if ($opendir = opendir($dir)) { //read directory while (($file=readdir($opendir)) !==FALSE) { if ($file!="."&&$file!="..") echo "
"; } } ?> Untitled Document

Hi there,

Try the following (not tested, but should do what you want):
[php]$files = scandir($dir);
$files = preg_grep(’/[.]+/’,$files,PREG_GREP_INVERT);
sort($files);
foreach($files as $file)
{
if(is_file($file))
{
echo $file;
}
}[/php]

hi and thank you! ive just tried your code but it just returns a blank page is that normal if so how do i display the images with in the folder any ideas this is what i have done so far with your code

[php]

<?php $dir = "img/thumbs"; $files = scandir($dir); $files = preg_grep('/[\.]+/',$files,PREG_GREP_INVERT); sort($files); foreach($files as $file) { if(is_file($file)) { echo $file; } } ?>[/php]

Sorry my bad, change the preg_grep line to this:
[php]$files = preg_grep(’/^(.|..)$/’,$files,PREG_GREP_INVERT);[/php]

Then you can do something like:
[php]
if(is_file($file))
{
echo ‘’;
}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service