簡體   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