我在浏览器中回显图像时遇到了一些困难。我对PHP很陌生,在过去的一个小时里我一直在网上搜索,但没有找到解决方案。我曾尝试将header('Content-Type: image/jpeg');
添加到文档中,但它什么都不做。我希望我的代码能够扫描目录,并将其所有图像文件放入$ thumbArray中,然后我将回显给浏览器。我的最终目标是照相馆。将图像插入数组可以正常工作,但不会在页面上显示它们。这里是我的我的代码:难以回应JPEG图像
<?php
//Directory that contains the photos
$dir = 'PhotoDir/';
//Check to make sure the directory path is valid
if(is_dir($dir))
{
//Scandir returns an array of all the files in the directory
$files = scandir($dir);
}
//Declare array
$thumbArray = Array();
foreach($files as $file)
{
if ($file != "." && $file != "..") //Check that the files are images
array_push($thumbArray, $file); //array_push will add the $file to thumbarray at index count - 1
}
print_r($thumbArray);
include 'gallery.html';
?>
继承人的Gallery.html文件:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Gallery</title>
</head>
<body>
<?php
header('Content-Type: image/jpeg');
for($i = 0; $i < count($thumbArray); $i++)
echo '<img src="$dir'.$thumbArray[$i].'" alt="Picture" />';
?>
</body>
</html>
'''' – Petah
用你的替换我的线不能解决我的问题。我仍然可以看到带有折页角的小方框,而不是我的图像。 – Whoppa