save a image in database function
by Prakash[ Edit ] 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);