Dymond
Dymond

Reputation: 2277

show files from folder as thumbnails php

Im trying to rezise some images that are imported from a folder. It doesent matter if it only show the realpicture as a thumbnail since the size of the file wont be much larger than 500kb,

Is there a way I can make the images as clickable images ? I have google it , but cant seem to find a solution that helps me.

This is the code that reads from the folder

$files = glob("uploads/*.*"); 

for ($i=1; $i<count($files); $i++) 
{
     $num = $files[$i];
     echo '<img src="'.$num.'" alt="random image">'."&nbsp;&nbsp;";      
}

Upvotes: 0

Views: 3719

Answers (2)

user836352
user836352

Reputation:

I'm not sure how to actually resize the images with PHP to reduce the file size, but to make the browser render them at a small 'thumbnail' size just add a CSS class attribute to the images that are pushed out. Something like this:

echo '<img class="thumb" src="'.$num.'" alt="random image">'."&nbsp;&nbsp;";

Then, just add some CSS for the img.thumb class to the top of your document, or wherever you have the rest of your CSS:

img.thumb
{
width:50px;
height:50px;
}

If you want the images to by clickable (presumably linking to the full-size image), just wrap anchor tags around your img tags when echo'ing to the document. Something like this:

echo '<a href="' . $num . '"><img src="'.$num.'" alt="random image"></a>'."&nbsp;&nbsp;";

Upvotes: 2

galchen
galchen

Reputation: 5290

clickable means links

for ($i=0, $n=$i<count($files); $i<$n; $i++) {
    $num = $files[$i];
    echo '<a href="/path/to/uploads/'.$num.'" target="_blank">'
        .'<img src="'.$num.'" alt="random image">'
        .'</a>&nbsp;&nbsp;';
}

or you can do it with javascript, but this is easier

Upvotes: 0

Related Questions