tags:

views:

470

answers:

5

How to fetch the images from a folder and display it in the page, whether i can resize it in php itself or i have to resize it and upload it separtely to display it as thumbnails?

+2  A: 

Here's the basic structure for traversing a directory and doing something with the image files (given 'images' is a directory in the same directory of your script)

$image_types = array(
    'gif' => 'image/gif',
    'png' => 'image/png',
    'jpg' => 'image/jpeg',
);

for ($entry in scandir('images')) {
    if (!is_dir($entry)) {
        if (in_array(mime_content_type('images/'. $entry), $image_types)) {
            // do something with image
        }
    }
}

From here, you can send the images directly to browser, generate tags for HTML page or create thumbnails with GD functions and store them for displaying.

Imran
+1  A: 

i think this may help you!

<?
$string =array();
$filePath='directorypath/';  
$dir = opendir($filePath);
while ($file = readdir($dir)) { 
   if (eregi("\.png",$file) || eregi("\.jpg",$file) || eregi("\.gif",$file) ) { 
   $string[] = $file;
   }
}
while (sizeof($string) != 0){
  $img = array_pop($string);
  echo "<img src='$filePath$img'  width='100px'/>";
}
?>
Srikanth
A: 

It has helped very much.

Oteyo
A: 

THANK YOU SO MUCH!!!:D

eva marie