从文件夹加载图像列表 [英] Load list of image from folder

查看:91
本文介绍了从文件夹加载图像列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从10到200的图像文件夹,一个网页,一个jquery淡入淡出和一个php脚本,可读取充满图像的文件夹

I have a folder of images, from 10 to 200, a webpage, a jquery fade and a php script that read folder full of images

有什么方法可以使php脚本扫描文件夹,获取图像列表(在数组中?)并将其传递给jquery脚本? (第一个问题)

Is there any way to make the php script scan a folder, get a list of image (in an array ?) and pass it to jquery script ? (first question)

现在,我可以从找到的文件的结果php列表中创建xml文件,或者从html中的列表中创建html <li>.还有其他方法吗? (问题2)

Now, i can make a xml file from the result php list of files found or make a html <li> from the list in the html. is there ANY other way to do that ? (question #2)

推荐答案

要从

To continue on from nickf's excellent answer, this is slightly more robust for images of different types.

$imagesDir = 'path/to/your/images/';
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);

echo json_encode($images);

还有其他方法可以做到这一点,但这是最简单的.请注意,某些文件系统区分大小写,因此请确保扩展名列表与您要查找的文件完全匹配.

There are other ways of doing this, but this is the easiest. Note some file systems are case sensitive, so ensure the extension list is matching precisely what you're after.

这篇关于从文件夹加载图像列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆