当前位置: 动力学知识库 > 问答 > 编程问答 >

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

问题描述:

I have a php page which retrieves the full url of a remote image and then it has to display it. But im getting the error 'cannot be displayed because it contains errors'. I need this script for an app. Can someone point out error here?

The url is working perfectly because when i echo the url..it is echoing it correctly. So im assuming the error is coming in the imag header or something. please help.

Please note that the database stores the file name of the jpeg...for 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);

?>

网友答案:

Try this: this code put in the top of your code..

/ 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);

More Info

网友答案:

Your problem lies in the way you're outputting the image using PHP.

If you have an image file on the server, and wish to stream it to the browser, try using the example code from this PHP documentation page:

http://php.net/manual/en/function.imagecreatefromjpeg.php (Example #1)

If you have the URL to an image located on another web server, and wish to show it using HTML try this line:

print "<img src='$url' alt=''>";
分享给朋友:
您可能感兴趣的文章:
随机阅读: