readdir - php read directory sorting -
i have little php script reads directory , echos files (jpg's in case) jquery image slider. works perfectly, dont know how sort images name desending. @ moment images random.
<?php $dir = 'images/demo/'; if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { echo '<img src="'.$dir.$file.'"/>'; } closedir($handle); } ?>
any on great.
one more thing dont understand. script pics 2 nameless non jpg files in folder not exist??? havnt realy checked yet
try this:
$dir = 'images/demo/'; $files = scandir($dir); rsort($files); foreach ($files $file) { if ($file != '.' && $file != '..') { echo '<img src="' . $dir . $file . '"/>'; } }
Comments
Post a Comment