【发布时间】:2012-05-05 10:21:23
【问题描述】:
我正在使用 php 从目录中检索图像。图像显示在 PHP 页面 (getUser.php) 上,但这些图像如何显示在任何 HTML 上。
getUser.php
<?php
$dir = 'images';
$file_display = array('jpg','jpeg','png','gif');
if (file_exists ($dir) == false) {
echo 'Directory \'', $dir, '\' not found!';
}
else{
$dir_contents = scandir($dir);
foreach($dir_contents as $file) {
$file_type = strtolower(end(explode('.', $file)));
If($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true) {
echo '<img src="', $dir, '/', $file, '" alt="', $file, '" />';
/*echo '<td>';
echo '<img src =';
echo $dir."/".$file;
echo '/>';
echo '</td>'; */
}
}
}
?>
one.html
我希望这个图像数组以 html (div) 显示。那就是从 PHP 文件中读取图像标签的来源。我已经在 ASP.NET 中做到了这一点,但在 PHP 中无法弄清楚有没有类似的东西
<img src="images/vimages/<%=row["image"] %>" ASP.NET
这个 PHP。
<div id="pics">
<img src="img/...jpg" alt="" />
</div>
上面的 div 将使用 getUser.php 文件动态填充。
【问题讨论】:
-
那么什么不起作用?在任何 html 上意味着什么?
-
@DenisErmolin 数组中的图像通过回声显示。但我希望它们通过
标签显示,即在 HTML 页面中。我将如何做到这一点
-
我建议您重新提出您的问题。很难理解你想要什么。而且它与图像并没有真正的关系,所以我会改变标题。
标签: php image html html-parsing