PHP 列出文件夹中的图像

发布于 2024-09-14 02:17:36 字数 631 浏览 4 评论 0原文

我有以下代码

    // Define the full path to your folder from root 
    $path = "../galleries/".$album; 

    // Open the folder 
    $dir_handle = @opendir($path) or die("Unable to open $path"); 

    // Loop through the files 
    while ($file = readdir($dir_handle)) { 

              if(strlen($file)>1){echo "<a href='http://minification.com/?page_id=32&dir=$album&img=$file'><img src='http://minification.com/galleries/$album/$file'></a>";}

    } 

    // Close 
    closedir($dir_handle); 

我想要做的是从文件夹中提取所有图像并使用 PHP 显示它们。到目前为止,它的工作原理是只显示文件夹中的一张图像。有人知道如何解决这个问题吗?

I have the following code

    // Define the full path to your folder from root 
    $path = "../galleries/".$album; 

    // Open the folder 
    $dir_handle = @opendir($path) or die("Unable to open $path"); 

    // Loop through the files 
    while ($file = readdir($dir_handle)) { 

              if(strlen($file)>1){echo "<a href='http://minification.com/?page_id=32&dir=$album&img=$file'><img src='http://minification.com/galleries/$album/$file'></a>";}

    } 

    // Close 
    closedir($dir_handle); 

What i want to do is pull in all the images from a folder and display them using PHP. So far its working up to the point where it only displays one image out of the folder. Anyone know how to fix this?

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

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

发布评论

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

评论(3

等风也等你 2024-09-21 02:17:36

你的第二个文件可能评估为 false,请参阅 readdir(),你应该这样做:

while (false !== ($file = readdir($dir_handle))) {

Your second file probably evaulates to false, see readdir(), you should do:

while (false !== ($file = readdir($dir_handle))) {
奈何桥上唱咆哮 2024-09-21 02:17:36

提示:如果这是 PHP 5,您可以使用 来减少一些麻烦改为 scandir

Hint: If this is PHP 5, you can reduce the hassle a bit by using scandir instead.

一世旳自豪 2024-09-21 02:17:36

试试这个:

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

在 php 中许多不同的值评估为 false,因此您可能会得到误报。

try this:

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

A lot of different values evaluate to false in php so you may be getting a false positive.

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