Load Images from array in php



I’m building a web gallery for a client how it works is I have all the thumbnails in a folder and load them into an array with php. All the images are labeled sequentially. On my localhost, I iterate through the list and display all the thumbnails and they display in the same order that they were suposed to load into the array. however when the site is uploaded to dreamhost the order does not work or make sense. Any ideas as to why it would differ online from my local testing server? I can’t see anything wrong with the logic…



<?php //a list of support file types to allow in the gallery $allowed_filetypes = array('.jpg','.gif','.png','.bmp'); //$path_thumnails represents the location of the thumbnails to show in gallery $path_thumnails = opendir("content/img/felts/thumbnails/"); $path_topView = opendir("content/img/felts/top_views/"); $path_extraView = opendir("content/img/felts/extra_views/"); //create arrays to store the varying pictures by use $thumbnail_array = array(); $topView_array = array(); $extraView_array = array(); /* * While there is another file in each folder of images. Store the name of the file in the * corresponding array. */ $i= 0; while (false !== ($entry = readdir($path_thumnails))){ $ext = substr($entry,strpos($entry,'.'),strlen($entry)-1); if(in_array($ext,$allowed_filetypes)) { $thumbnail_array[$i] = $entry; $i++; } } $i= 0; while (false !== ($entry = readdir($path_topView))){ $ext = substr($entry,strpos($entry,'.'),strlen($entry)-1); if(in_array($ext,$allowed_filetypes)) { $topView_array[$i] = $entry; $i++; } } $i= 0; while (false !== ($entry = readdir($path_extraView))){ $ext = substr($entry,strpos($entry,'.'),strlen($entry)-1); if(in_array($ext,$allowed_filetypes)) { $extraView_array[$i] = $entry; $i++; } } /* * Loop that adds images to the gallery */ for($i=0; $i < sizeof($thumbnail_array)-1 ; $i++) { //add thumbnail of top view to gallery and link to full size image echo " "; //store the current rug number from name of image file $pattern = substr($topView_array[$i],0,6); //for each additional image containing the same rug number as the pattern store hidden in shadowbox gallery foreach($extraView_array as $img){ $pos = strpos($img, $pattern); if($pos !== false){ echo ""; } } }closedir($path_thumnails); closedir($path_topView); closedir($path_extraView); ?>



Why aren’t you doing any sorting?


I thought as long as I named them sequentially and it was working on the local host it would work fine but I assumed wrong I guess. I will try a sorting method. Plus I just started php this month so I’m still trying to get a grip on how to incorporate it. I’m not sure why I haven’t tried to sort my arrays yet though other than trying to get away with less code =P Thanks for the suggestion

That solved the problem thank you so much =)