Re: cant view image from database
| From: | Stuart Dallas | Date: | Thu, 12 Feb 2015 18:44:35 +0000 |
| Subject: | Re: cant view image from database | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324438@lists.php.net to get a copy of this message | ||
On Thursday, Feb 12, 2015 at 6:22 pm, Bastien Koert <phpster@gmail.com>, wrote:
You're echoing out an image tag, you just need to echo out the image
header("Content-type: image/jpeg");
$row = mysqli_fetch_array($result);
$img = $row["image"];
echo $img;
And at the very least you need to be using mysqli_real_escape_string, and not addslashes!
http://php.net/mysqli.real-escape-string
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
On Thu Feb 12 2015 at 12:31:23 PM hadi <almarzuki2011@hotmail.com> wrote:
> Hi,
>
> I can't view my image from mysql database.
> I used curl to download the image to mysql database, and im trying to view
> the image, im getting error from firefox debugger.
>
> Here is my code for downloading the image
>
> <?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);
>
> ?>
>
> And the code for viewing the image as flow;
>
> <!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
> #header("Content-type: image/jpeg");
>
> $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 error code:
>
> <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
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>