2014-01-28 55 views
0

我想用这个,所以我可以列出所有的图片在我有一个文件夹,然后使用一些CSS,使它看起来不错,但这不断显示在html中使用php来显示文件夹内的图像

'; }}?>

在图像应该是

<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> 
+0

因此,当您在浏览器中查看源代码时,您可以看到您的PHP代码? –

+0

似乎对我很好;你在服务器上运行它? – Daedalus

+0

我在iPad上的lighttpd服务器上运行它,当我查看它显示的页面时; }}?> – H4unt3r

回答

0

我会用DirectoryIterator类搜索内容的文件夹

向我们展示了在目录中的所有文件和目录,除了“内“。和“..”。

<?php 

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

?> 
+0

这并不是说实际的搜索部分不工作,如果我把代码的php部分放入test.php并打开它,它会完美地显示图像 – H4unt3r

相关问题