Storing images in mysql database

Storing images in mysql database

Mysql database can be used to store images, in other words as an image library. You ‘ll store the data using a “blob” type here.
At first read the image as byte format then store. if image length is less than 149000, then it can be done.

sample coding

$instr = fopen(”image.jpg”,”rb”);
$image = addslashes(fread($instr,filesize(”image.jpg”)));
if (strlen($instr) < 149000) {
mysql_query (”insert into pix (title, imgdata) values (”Image”, \”".$image.”\”)”);
} else {
$errmsg = “Too large!”;
}

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.