我想为我的域(我的互联网根文件夹)下的所有图像制作一个画廊。所有这些图像都在不同的文件夹中。“浏览”所有文件夹并返回图像的最佳方式是什么?
问问题
1238 次
4 回答
1
使用谷歌图片搜索作为site: www.mydomainwithimages.com
搜索词,这将显示你所有的索引图像。这应该是您域中的所有内容,只要您的 robots.txt 文件不排除 Google 抓取工具。
于 2010-03-22T13:10:43.757 回答
1
看一下opendir你会想要编写一个在递归循环中调用的函数,该函数可以遍历特定目录中的文件,检查文件扩展名并将文件作为数组返回,你将与全局合并大批。
于 2010-03-22T13:02:44.367 回答
0
取决于托管系统,您可以使用带有 exec 或 passthru 的命令行
find /path/to/website/root/ -type f -name '*.jpg'
如果你不能像火所说的那样做这样的事情,那么 opendir 就是要走的路。
于 2010-03-22T13:38:38.503 回答
0
我会给 PHP 的DirectoryIterator一个旋转。
这是未经测试的伪代码,但它应该像这样工作:
function scanDirectoryForImages($dirPath)
{
$images = array();
$dirIter = new DirectoryIterator($dirPath);
foreach($dirIter as $fileInfo)
{
if($fileInfo->isDot())
continue;
// If it's a directory, scan it recursively
elseif($fileInfo->isDir())
{
$images = array_merge(
$images, scanDirectoryForImages($fileInfo->getPath())
);
}
elseif($fileInfo->isFile())
{
/* This works only for JPEGs, oviously, but feel free to add other
extensions */
if(strpos($fileInfo->getFilename(), '.jpg') !== FALSE)
{
$images[] = $fileInfo->getPathname();
}
}
}
return $images;
}
如果这不起作用,请不要起诉我,这真的有点像我的帽子,但是使用这样的功能将是解决你的问题的最优雅的方法,恕我直言。
// 编辑:是的,这与火指出的基本相同。
于 2010-03-22T14:02:04.873 回答