php list output images in a directory

Solutions on MaxInterview for php list output images in a directory by the best coders in the world

showing results for - "php list output images in a directory"
Caterina
23 Apr 2018
1<?php
2
3echo scanDirectoryImages("uploads");
4
5/**
6* Recursively search through directory for images and display them
7* 
8* @param  array  $exts
9* @param  string $directory
10* @return string
11*/
12function scanDirectoryImages($directory, array $exts = array('jpeg', 'jpg', 'gif', 'png'))
13{
14if (substr($directory, -1) == '/') {
15    $directory = substr($directory, 0, -1);
16}
17$html = '';
18if (
19    is_readable($directory)
20    && (file_exists($directory) || is_dir($directory))
21) {
22    $directoryList = opendir($directory);
23    while($file = readdir($directoryList)) {
24        if ($file != '.' && $file != '..') {
25            $path = $directory . '/' . $file;
26            if (is_readable($path)) {
27                if (is_dir($path)) {
28                    return scanDirectoryImages($path, $exts);
29                }
30                if (
31                    is_file($path)
32                    && in_array(end(explode('.', end(explode('/', $path)))),   $exts)
33                ) {
34                    $html .= '<a href="' . $path . '"><img src="' . $path
35                        . '" style="max-height:100px;max-width:100px" />  </a>';
36                }
37            }
38        }
39    }
40    closedir($directoryList);
41}
42return $html;
43}
queries leading to this page
php code show images in folderfile paths in javaphp list output images in a directoryhow to extract images from a folder in phpphp add images from folderphp function to get all images in directoryphp show all images in directoryphp display all images in folder with gridphp get images from foldersearch every image phpphp fetch images from folder using searchprint the names of all images in a folder htmlphp display photos from a directoryreturning an image of directoryhow to print contents of current directory in linuxextract images from a folder in phpphp list images in directoryphp get all images in directoryphp get and display all jpeg images in folderphp extract image and send to a img folderhow to show all image folder phpphp load image from directorydisplay all images in a folder phpdisplay image in from folder in php how to show all image folder php htmlhow to show online images in php arraydisplay all images php out foldershow all images in file phpphp display all images in folder with their namesphp display all image in directoryimeage path script phpimage path 2fphp scripthow to call csv file in same directory pythontake all the folder images and process phpphp list image files in directoryphp show images from folderimages from folder phpphp show img from folderget all videos from specified local drive using php and display itphp show all images in folderphp show all pictures in directoryphp show all images in a directoryphp display images in directoryphp list output images in a directory