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

当访问目录中的图像时,图像不显示在php中,php,html,Php,Html,我正在学习php编程,最近我使用php文件访问目录以显示网页中的图像,但不能这样做。我正在粘贴chrome中出现的源代码和页面源代码。选中后,路径看起来是正确的,在浏览器中唯一可见的是图像缩略图 PHP代码 <!DOCTYPE html> <html> <head> <title>Displaying Images within a directory</title> </head> <body> <

我正在学习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>

在目录中显示图像
**浏览器中显示的HTML源代码**
在目录中显示图像


问题到底是什么,您希望得到什么?首先在浏览器开发控制台的“网络”选项卡中检查浏览器作为对图像的请求返回的结果。您可以在http服务器的访问和错误日志文件中看到相同的内容。我可能是因为文件系统权限而拒绝访问。这是您必须检查的,因为只有您可以访问您的系统。我们在这里帮不了什么忙尝试
$imagename='/house/'.$key。这可能有帮助,或者没有…@jeroen先生,我希望在浏览器中显示图像,但我没有得到任何图像。我刚得到那些小缩略图。另外,每当我单击图像源时,就会显示无法访问目录。@KIKOSoftware这很有效,非常感谢:)到底是什么问题,与您得到的相反,您期望得到什么?首先在浏览器开发控制台的“网络”选项卡中,检查浏览器作为对图像的请求返回的结果。您可以在http服务器的访问和错误日志文件中看到相同的内容。我可能是因为文件系统权限而拒绝访问。这是您必须检查的,因为只有您可以访问您的系统。我们在这里帮不了什么忙尝试
$imagename='/house/'.$key。这可能有帮助,或者没有…@jeroen先生,我希望在浏览器中显示图像,但我没有得到任何图像。我刚得到那些小缩略图。另外,每当我单击图像源时,就会显示无法访问目录。@KIKOSoftware这很有效,非常感谢:)