PHP 图像标头错误,无法显示 get,因为它包含错误


php image header error, getting cannot be displayed because it contains errors?

我有一个php页面,它检索远程图像的完整url,然后它必须显示它。但是我收到错误"无法显示,因为它包含错误"。我需要这个应用程序的脚本。有人可以在这里指出错误吗?

网址

运行良好,因为当我回显网址时。它正确地呼应了它。所以我假设错误出现在 imag 标头或其他东西中。请帮忙。

请注意,数据库存储jpeg的文件名...例如。文件名.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/en/function.imagecreatefromjpeg.php(示例 #1)

如果您有位于其他Web服务器上的图像的URL,并希望使用HTML显示它,请尝试以下行:

print "<img src='$url' alt=''>";