How to read pictures in a folder?

WBOY
Release: 2016-08-18 09:16:25
Original
1472 people have browsed it

This can display a picture, but what should I do if I want to display all the pictures in the img folder? It doesn't work if I change it to $url = 'upload/'; So what should I do?

<code>header("Content-Type: image/jpeg;text/html; charset=utf-8");
$url='1.jpg';
$img = file_get_contents($url,true);
echo $img;</code>
Copy after login
Copy after login

Reply content:

This can display a picture, but what should I do if I want to display all the pictures in the img folder? It doesn't work if I change it to $url = 'upload/'; So what should I do?

<code>header("Content-Type: image/jpeg;text/html; charset=utf-8");
$url='1.jpg';
$img = file_get_contents($url,true);
echo $img;</code>
Copy after login
Copy after login

There are many methods, examples are as follows

<code>$dir = "upload/";  //要获取的目录
if (is_dir($dir)){
    if ($dh = opendir($dir)){
        while (($file = readdir($dh))!= false){
            $filePath = $dir.$file;
            echo "<img src='".$filePath."'/>";
        }
        closedir($dh);
    }
}</code>
Copy after login
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!