如何将目录中的图像和文件回显到页面php

问题描述 投票:0回答:2
if ($handle = opendir('.')) {

    while (false !== ($entry = readdir($handle))) {

        if ($entry != "." && $entry != ".." && !in_array($entry, $blacklist)) {
            echo "<p>$entry\n</p>";
        } 


    }

    closedir($handle);
}

以上是我用来回显目录中所有文件的PHP代码。它工作正常,但页面回显了此内容:

example.html的

test.php的

image.png

mobile.html

的text.txt

image2.jpg

我如何做到这一点,如果目录中的文件是图像,则显示为图像而不是文本。例如,页面将回显:

example.html的

test.php的

((来源:treehugger.com]

mobile.html

的text.txt

简而言之,我当前使用的代码仅显示目录中每个文件的名称。我希望它显示目录中每个文件的名称,但是,如果目录中有图像,则不回显图像的文件名,而是显示图像。

if($ handle = opendir('。')){while(false!==($ entry = readdir($ handle))){if($ entry!=“。” && $ entry!=“ .. “ &&!in_array($ entry,$ blacklist)){echo”&...

php file directory echo
2个回答
1
投票

如果您只想获取图像,这应该对您有用:


0
投票

尝试这个:

© www.soinside.com 2019 - 2024. All rights reserved.