lunac Posted September 20, 2006 Share Posted September 20, 2006 I wrote a quick and dirtly little script that allows me to drop some comp images into folders for my clients for them to view. Basically it looks at a directory/file and changes it's name from 1MyLittlePumpkin to My Little Pumkin. These show in a list with thumbnails below the directory name. [url=http://www.bythemoon.com/clientfiles/tucker/comp/]See example...[/url]I hoped to be able to sort directories and files by the number I placed in front, but I can't figure it out. Any guidance would be appreciated.[code=php:0]$fdir = opendir(".");while($folder = readdir($fdir)){ $start = substr($folder, 0, 1); if($start != "." and $folder != "index.php" and $folder != "image.php"){ $ftitle = substr($folder, 1); $ftitle = preg_replace("/([A-Z0-9])/", " $1", $ftitle); echo "<h4>$ftitle </h4>"; $dir = opendir($folder);while($file = readdir($dir)){ $start = substr($file, 0, 1); if($start != "."){ $title = substr($file, 1); $title = preg_replace("/\..*?$/", "", $title); // removes the extension $title = preg_replace("/([A-Z0-9])/", " $1", $title); // places the space echo '<div class="thumb"><a href="image.php?folder=' . $folder . '&img=' . $file . '" target="view"><img src="' . $folder . "/" . $file . '"></a><br />' . $title . '</div>'; }}[/code] Quote Link to comment Share on other sites More sharing options...
btherl Posted September 20, 2006 Share Posted September 20, 2006 [code]$files = array();while ($file = readdir($dir)) { $start = substr($file, 0, 1); if ($start != ".") { $files[] = $file; }}sort($files)foreach ($files as $file) { $title = substr($file, 1); $title = preg_replace("/\..*?$/", "", $title); // removes the extension $title = preg_replace("/([A-Z0-9])/", " $1", $title); // places the space echo '<div class="thumb"><a href="image.php?folder=' . $folder . '&img=' . $file . '" target="view"><img src="' . $folder . "/" . $file . '"></a><br />' . $title . '</div>';}[/code]That ought to work. Instead of reading the files and displaying them immediately, you will be reading them into an array, sorting the array, then displaying them. I've left the filtering of "." files in the first foreach, so you don't need to do it again in the second one.. Quote Link to comment Share on other sites More sharing options...
lunac Posted September 21, 2006 Author Share Posted September 21, 2006 That worked perfectly on the files! Thanks.I tried that method on the folders, but I must be doing it wrong. And guidance there ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.