域下的所有可用图像

发布于 2024-08-26 06:23:02 字数 80 浏览 7 评论 0原文

我想制作一个包含我的域(我的互联网根文件夹)下的所有图像的画廊。所有这些图像都位于不同的文件夹中。 “浏览”所有文件夹并返回图像的最佳方式是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

才能让你更想念 2024-09-02 06:23:02

使用 Google 图片搜索,并将 site: www.mydomainwithimages.com 作为搜索字词这将向您显示所有索引图像。只要您的 robots.txt 文件不排除 Google 抓取工具,这应该是您域中的所有内容。

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.

时光暖心i 2024-09-02 06:23:02

看看 opendir 你会想写一个函数在递归循环中调用,该函数可以循环特定目录中的文件,检查文件扩展名并将文件作为数组返回,您将与全局数组合并。

Take a look at opendir you would want to write a function that gets called in a recursive loop, the function could loop through the files in the specific directory, check the file extension and return the files as an array which you would merge with a global array.

八巷 2024-09-02 06:23:02

取决于托管系统,您可以使用带有 exec 或 passthru 的命令行。

find /path/to/website/root/ -type f -name '*.jpg'

如果您不能做这样的事情,正如 fire 所说,opendir 是可行的方法。

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.

怪我入戏太深 2024-09-02 06:23:02

我想尝试一下 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;
}

如果这不起作用,请不要起诉我,这确实有点来自我的帽子,但使用这样的函数将是最优雅的解决你的问题的方法,恕我直言。

//编辑:是的,这与火指出的基本相同。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文