繁体   English   中英

使用 php 显示来自 ftp 服务器的图像

[英]Display images from ftp server with php

如何使用 php 在网站中显示来自 ftp 服务器的所有图像? 它也应该自动排序,所以我可以将更多图像添加到 ftp 服务器,它会工作。

我正在尝试制作画廊类型的东西

我已经浏览了谷歌并没有发现任何有用的东西。 我还在学习 php 并不太了解它。

任何帮助将非常感激。 谢谢!

正如已经评论过的, scandir可以解决问题。 下面的代码将所有图像和 output 作为<img>元素。

index.php

// Here enter the base url of the images folder 
$base_images_url = "http://example.com/images/";

$dir = dirname (__FILE__) . "/images/";

// Get the files in the folder. Sort in ascending order - this is the default
$images = scandir($dir);

// Or is you need to sort in descending order
//$images = scandir($dir,1);

// Output an img tag for every image.
foreach($images as $image){
    // skip the . and .. that starts the folder listing
    if($image === '.' || $image === '..'){
        continue;
    }
    $image_url = $base_images_url . $image;
    echo '<img src="' . $image_url . '">';
}

这适用于以下文件夹设置:

-index.php
-images
   -image1.png
   -anotherimage.jpg

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM