簡體   English   中英

在html中使用php從文件夾中顯示圖像

[英]Using php in html to display images from within a folder

我正在嘗試使用此功能,因此我可以列出我擁有的文件夾中的所有圖片,然后再使用一些CSS使它看起來不錯,但這一直在顯示

'; }}?>

圖片應該在哪里

<body>
<h1>Laughing out loud</h1>
<?php
$handle = opendir(dirname(realpath(__FILE__)).'/images/');
while($file = readdir($handle)){
    if($file !== '.' && $file !== '..'){
         echo '<img src="images/'.$file.'" border="0" />';
    }
}
?>
<p>To</p>
</body>

我將使用DirectoryIterator類在文件夾內搜索內容

向我們顯示目錄中除“。”以外的所有文件和目錄。 和“ ..”。

<?php

foreach (new DirectoryIterator('../yourfolder') as $fileInfo) {
     if($fileInfo->isDot()) continue;
     echo $fileInfo->getFilename() . "<br>\n";
 }

?> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM