[英]php image header error, getting cannot be displayed because it contains errors?
我有一個php頁面,它檢索遠程圖像的完整URL,然后必須顯示它。 但是我收到錯誤“由於包含錯誤而無法顯示”。 我需要一個應用程序的腳本。 有人可以在這里指出錯誤嗎?
該URL正常工作,因為當我回顯url ..時,它正確地回顯了它。 因此,我假設錯誤出現在imag標頭或其他內容中。 請幫忙。
請注意,數據庫存儲jpeg的文件名,例如ex..filename.jpg
<?php
if (isset($_GET['id'])){
$id = $_GET['id'];
}
$username="--";
$password="--";
$hostname = "xxxx";
//connection string with database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
// connect with database
$selected = mysql_select_db("1775125_tourist",$dbhandle)
or die("Could not select examples");
$query = mysql_query("Select * FROM photo_details WHERE place_id = '$id'");
while($row = mysql_fetch_assoc($query)){
$imageData = $row["photo"];
}
$url = "http://optimusone.net46.net/testing_only/uploads/".$imageData;
header('Content-Type: image/jpg');
imagejpeg($url);
?>
試試看:此代碼放在您的代碼頂部。
/ Report all PHP errors (see changelog)
error_reporting(E_ALL);
// Report all PHP errors
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
您的問題在於使用PHP輸出圖像的方式。
如果服務器上有圖像文件,並且希望將其流式傳輸到瀏覽器,請嘗試使用此PHP文檔頁面中的示例代碼:
http://php.net/manual/zh/function.imagecreatefromjpeg.php (示例1)
如果您擁有位於另一台Web服務器上的圖像的URL,並希望使用HTML進行顯示,請嘗試以下行:
print "<img src='$url' alt=''>";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.