Current time: 04-24-2014, 01:54 AM Hello There, Guest! (LoginRegister)

Post Reply 
Load Images from array in php...
04-09-2012, 07:53 PM
Post: #1
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...

http://crumdesigns.net/gallery.php

PHP Code:
<?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.
                    */
                    
$i0;
                    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++;
                        }
                    }
                    
                    
$i0;
                    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++;
                        }                    
                    }
                    
                    
$i0;
                    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)-$i++) {
                        
                        
//add thumbnail of top view to gallery and link to full size image
                        
echo "<a href=\"content/img/felts/top_views/$topView_array[$i]\" rel=\"shadowbox[test1]\" title=\"$topView_array[$i] -- photo by: Chris Rigg\" >
                                <img src=\"content/img/felts/thumbnails/$thumbnail_array[$i]\" width=\"250px\" height=\"150px\" /></a>"
;
                        
                        
//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 
"<a href=\"content/img/felts/extra_views/$img\" rel=\"shadowbox[test1]\" title=\"$img\" ></a>";
                            }
                        }
                        
                    }
closedir($path_thumnails); closedir($path_topView); closedir($path_extraView);
?>
Find all posts by this user
Quote this message in a reply
04-09-2012, 08:22 PM
Post: #2
RE: Load Images from array in php...
Why aren't you doing any sorting?

Customer since 2000 Cool openvein.org | Please don't feed the trolls. Angry
Visit this user's website Find all posts by this user
Quote this message in a reply
04-09-2012, 08:24 PM (This post was last modified: 04-09-2012 09:12 PM by crum_nathan.)
Post: #3
RE: Load Images from array in php...
(04-09-2012 08:22 PM)Atropos7 Wrote:  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


**Edit**
That solved the problem thank you so much =)
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: