save a image in database function

by Prakash 2013-07-01 16:50:34

The following php function saves a image file to the database :


function saveImgDatabase($filename){
$fileo = @fopen($filename,"rb");
if(!$fileo)
{
return false;
}
$imgData = addslashes(file_get_contents($filename));
$qry ="insert into mytable set myimage='$imgData'";
$res = mysql_query($qry) or die('Error in function'.mysql_error());
return $res;
}
//function end


Use the function as follows :

$filename = 'myimage.jpg';
saveImgDatabase($filename);
987
like
0
dislike
0
mail
flag

You must LOGIN to add comments