Home > Backend Development > PHP Tutorial > php如何获取文件夹中的图片

php如何获取文件夹中的图片

PHPz
Release: 2020-06-24 11:12:43
Original
3367 people have browsed it

php如何获取文件夹中的图片

php 读取文件夹下所有图片、文件的实例

如下所示:

$hostdir=dirname(__FILE__).'/data/upload/admin/20170517/'; //要读取的文件夹
 
$url = '/data/upload/admin/20170517/'; //图片所存在的目录
 
$filesnames = scandir($hostdir); //得到所有的文件
 
// print_r($filesnames);exit;
//获取也就是扫描文件夹内的文件及文件夹名存入数组 $filesnames
 
$www = 'http://www.***.com/'; //域名
 
foreach ($filesnames as $name) {
 $aurl= "<img width=&#39;100&#39; height=&#39;100&#39; src=&#39;".$www.$url.$name."&#39; alt = &#39;".$name."&#39;>"; //图片
 echo $aurl . "<br/>"; //输出他
}
Copy after login

更多相关技术文章,请访问PHP中文网

Related labels:
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