I'd like to make a gallery of all images i have under my domain (my internet root folder). All these images are in different folders. What's the best way to 'browse' through all the folders and return the images?
+1
A:
Use Google Image Search with site: www.mydomainwithimages.com
as the search term and this will show you all your indexed images. This should be everything in your domain as long as your robots.txt file doesn't exclude the Google crawler.
Dave Anderson
2010-03-22 13:10:43
Great solution. However i get some strange images from cn.last.fm in my search results also.. Any idea?
Paul
2010-03-22 13:25:50
This assumes that every image is linked to from some page that Google indexes.
meagar
2010-03-22 13:35:58
A:
Depends on hosting system, you could use command line with exec or passthru
find /path/to/website/root/ -type f -name '*.jpg'
If you can't do such a thing, as fire said, opendir is the way to go.
Benoit
2010-03-22 13:38:38
A:
I would give PHP's DirectoryIterator a spin.
This is untested pseudo-code, but it should work a little bit like this:
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;
}
Please don't sue me if this doesn't work, it's really kinda from the top of my hat, but using such a function would be the most elegant way to solve your problem, imho.
// edit: Yeah, that's basically the same as fire pointed out.
Turbotoast
2010-03-22 14:02:04