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



如何使用php在网站中显示ftp服务器上的所有图像?它还应该自动排序,这样我就可以在ftp服务器上添加更多的图像,这样它就可以工作了。

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

我已经浏览了谷歌,但没有发现任何有效的东西。我还在学习php,对它了解不多。

任何帮助都将不胜感激。谢谢

如前所述,scandir起到了关键作用。下面的代码获取所有图像并将它们作为<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

最新更新