无法从数据库中查看图像

时间:2015-02-12 17:40:39

标签: php

我无法从mysql数据库查看我的图像。 我使用curl将图像下载到mysql数据库,我试图查看图像,我从firefox调试器获取错误。

我已经在blob fromat中创建了我的数据库。

以下是我下载图片的代码

<?php

$servername = "localhost";
$username = "recorduser";
$password = "password123";
$database = "record";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $database); //    Check connection if (!$conn) {
die("Connection failed: " . mysqli_connect_error()); }


$ch = curl_init ("http://www.albaldnews.com/upimages/news/thumb_albald11-04- 2014-993734.jpg");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch,        CURLOPT_BINARYTRANSFER,1); 
$rawdata=curl_exec ($ch); 
curl_close ($ch);

$rawdata = addslashes($rawdata);


$sql = "INSERT INTO picture (image)VALUES ('$rawdata')"; 
$result =   mysqli_query($conn, $sql);

?>

用于查看图像流程的代码;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>dispaly image</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />         

</head>

<body>


<?php

$servername = "localhost";
$username = "recorduser";
$password = "password123";
$database = "record";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $database); 
//Check connection if (!$conn) {
die("Connection failed: " . mysqli_connect_error()); }

$sql = "SELECT * FROM picture";
$result = mysqli_query($conn, $sql);

header("Content-type: image/jpeg");
$row = mysqli_fetch_array($result);
$img = $row["image"];

echo '<img src="'.$img.'" />';


?>

Firefox错误代码:

<img src="http://192.168.206.129/rssfeed/showimage.php" alt="The image   “http://192.168.206.129/rssfeed/showimage.php” cannot be displayed because it   contain errors>

1 个答案:

答案 0 :(得分:1)

终于有效了。

我将echo $img;替换为echo $img = $row["image"];