RE: [PHP] cant view image from database
| From: | hadi | Date: | Thu, 12 Feb 2015 19:02:28 +0000 |
| Subject: | RE: [PHP] cant view image from database | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324440@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Bastien Koert [mailto:phpster@gmail.com]
> Sent: Thursday, February 12, 2015 9:22 PM
> To: hadi; php-general@lists.php.net
> Subject: Re: [PHP] cant view image from database
>
> 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;
I tried your code but not helping. Still getting error from firefox
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 contains errors>
> 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
> >
> >