PHP different locations for images and thumbs

195

I have found some solution that work mostly but none that do the trick 100% what I am looking for is code that will look in all my albums in one directory and pull the images and also pull my thumbs that are in another folder and echo out the a string like this.

echo '<a href="',$img,'" rel="shadowbox"><img src="',$img,'" /></a>';

The problem is that my href image is in my images folder and my src (thumbnails) are in another directory. I am using shadowbox and want the script to echo out a stirng that will allow both the directories to be scanned at the same time.

Below is what I am using that does scan the directorys but will not return the coresponding enter code herethumbnails that reside in another directory

//path to directory to scan. i have included a wildcard for a subdirectory
$directory = "gallery_uploads/*/";

//get all image files with a .jpg extension.
$images = glob("" . $directory . "*.jpg");

$imgs = '';
// create array
foreach($images as $image){ $imgs[] = "$image"; }


//display images
foreach ($imgs as $img) {
     "<a href='$img' rel='shadowbox'><img src='$img' /> ";


     echo'<a href="',$img,'" rel="shadowbox"><img src="',$img,'" /></a>';
64

Answer

Solution:

This works for me. You would have to make sure your images have the same name in each directory though.

It is very simple to have your uploader save the original, then save a resized image of the same name in the thumbnail directory.

$gallery_up_dir = "gallery_uploads";
$gallery_thumb_dir = "gallery_thumbs";
$directory = "$gallery_up_dir/*/";

// or get all image files with a .jpg, .JPG, .png, .PNG extension.
$extensions_array = array('jpg', 'JPG', 'png', 'PNG');


$imageArray = array();
foreach($extensionsArray as $ext){
    $images = glob("" . $directory . "*.$ext");

    // fill up the array
    foreach($images as $image){ 
        $imageArray[] = "$image"; 
    }
}

//display images
foreach ($imageArray as $img) {

     echo '<a href="',$img,'" rel="shadowbox"><img src="', 
           str_replace($gallery_up_dir,$gallery_thumb_dir,$img) ,'" /></a>';

}

People are also looking for solutions to the problem: php - session protection

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.