Rajasekar Rajasekar - 1 year ago 80
PHP Question

How to get the pictures from folder one by one and display in the page using PHP

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?

Answer Source

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.