要使用 PHP 从文件夹/目录中获取图像的标题(例如 abc.jpg)并将它们存储在数组中,应该怎么做。
例如:
a[0] = 'ac.jpg'
a[1] = 'zxy.gif'
等等
我将在幻灯片放映中使用该数组。
最佳答案
这当然是可能的。看看the documentation for opendir并将每个文件推送到结果数组。如果您使用的是 PHP5,请查看 DirectoryIterator .这是遍历目录内容的一种更流畅、更清晰的方法!
编辑:在 opendir 上构建:
$dir = "/etc/php5/";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
$images = array();
while (($file = readdir($dh)) !== false) {
if (!is_dir($dir.$file)) {
$images[] = $file;
}
}
closedir($dh);
print_r($images);
}
}
关于php - 获取目录中图像的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8414746/