RE: [PHP-DB] storing images in database

From: Date: Tue, 25 Jan 2005 17:45:39 +0000
Subject: RE: [PHP-DB] storing images in database
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-38326@lists.php.net to get a copy of this message
you can not ouput html and binary data at the same time. you need to have image headers sent to the browser to show the image properly. the best way to do this is to move the image processing code to a separate page and include it like this echo '<img src="./path/to/image.php?id=$id">'; then the image page looks like this: <?php if($_GET['id']) { $id = $_GET['id']; // you may have to modify login information for your database server: @MYSQL_CONNECT("localhost","root","password"); @mysql_select_db("binary_data"); $query = "select bin_data,filetype from binary_data where id=$id"; $result = @MYSQL_QUERY($query); $data = @MYSQL_RESULT($result,0,"bin_data"); $type = @MYSQL_RESULT($result,0,"filetype"); Header( "Content-type: $type"); echo $data; }; ?> bastien
From: Chip Wiegand <chip.wiegand@simrad.com> To: "PHP DB" <php-db@lists.php.net> Subject: [PHP-DB] storing images in database Date: Tue, 25 Jan 2005 09:11:07 -0800 I have stored a .jpg image in a database, then when I make a sql statement to display that image on a web page all I get is the cryptic code in place of the image. I am storing it in a row configured as a blob, mime type image/jpeg and binary (using phpMyAdmin). What am I doing wrong? Regards, Chip -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.db (#38326) next »