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?
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',
);
foreach (scandir('images') as $entry) {
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.
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'/>";
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With