[英]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.