图像不显示在php访问目录中的图像

时间:2016-07-01 12:33:05

标签: php html

我正在学习php编程,最近我使用php文件访问目录以在网页中显示图像但是不能这样做。我粘贴了chrome中出现的源代码和页面源代码。如图所示,路径似乎是正确的,只有在浏览器中可见的是图像缩略图

PHP代码

<!DOCTYPE html>
<html>
<head>
    <title>Displaying Images within a directory</title>
</head>
<body>
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
$dir = $root.'/house';
$opdir = opendir($dir);
if($opdir){
    $images = array();
    while(false !== ($file = readdir($opdir)))//keep on looping till you do not find any file in directory. analogous to fgets.!== means not identical and will be false when they are not equal or not of same type
    {
    if($file != '.' && $file!= '..');//they are directory files in windows pc so we have to skip them
    {
        array_push($images, $file);
    }
}
}
sort($images);
foreach ($images as $key) {
    $imagename = 'house/'.$key;
    print "<p><img src='".$imagename."'></p>\r\n";
}
?>
</body>
</html>







**HTML SOURCE AS SEEN IN BROWSER**

<!DOCTYPE html>
<html>
<head>
    <title>Displaying Images within a directory</title>
</head>
<body>
<p><img src='house/.'></p>
<p><img src='house/..'></p>
<p><img src='house/bayview_1.jpg'></p>
<p><img src='house/bayview_2.jpg'></p>
<p><img src='house/mallard_1.jpg'></p>
<p><img src='house/moduler_1.jpg'></p>
<p><img src='house/townhome_1.jpg'></p>
<p><img src='house/white_house.jpg'></p>

</body>
</html>

0 个答案:

没有答案