我在瀏覽器中回顯圖像時遇到了一些困難。我對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