Jump to content

Storing and Viewing Image via MySQL


sunziun

Recommended Posts

I am using this code to view the images from a database, table "slider"TABLE IN SQL

CREATE TABLE IF NOT EXISTS `slider` (  `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,  `caption` varchar(45) COLLATE latin1_general_ci NOT NULL,  `picture` blob,  `type` varchar(25) COLLATE latin1_general_ci NOT NULL,  `alt` varchar(65) COLLATE latin1_general_ci NOT NULL,  `width` int(11) NOT NULL,  `height` int(11) NOT NULL,  PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=4;

VIEW.PHP

<?phpmysql_connect("127.0.0.1", "root", "");mysql_select_db("f3wd");$sql = "SELECT * FROM `slider` WHERE `id` = 3 LIMIT 0, 30 ";$query = mysql_query($sql) or die(mysql_error());var_dump($query);echo $query;?>

it gives only: resource(3) of type (mysql result) Resource id #3my questions:1- how can i update the images directly in PhpMyAdmin?2- how can i view these images via browser?3- how can i view images PhpMyAdmin if necessary?thanks in adavanced!

Link to comment
Share on other sites

1) image is stored as binary as far i know you cant see the image through phpmyadmin it will show the binary format of the image not the picture itself.

2) i think echoing the picture with specifying the content type of images in header() will show you up the image

3) as for the same reason as 1 i think its hard to update an image through phpmyadmin$quey holds the return value of mysql_Query. mysql_Query the reource on success. to take out the data in it you have to do some mysql_fetch_assoc() or mysql_result() or mysql_fetch_array();

Link to comment
Share on other sites

thanks a lot.I'm just uploading the pictures without any further updates.how does the echo header image work. i would like to give a try.echo(header(pic.png));is that right?

Link to comment
Share on other sites

No. Header sends a raw HTTP header. In this case, you want to tell the web browser that the content being displayed is PNG data. You would do it like this:

header('Content-type: image/png');echo $imagedata;

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...