Saturday, June 5, 2010

How to convert base64 string into image with php?

 First of all create the base64 string
 
  function encode_img($img)
      {
           $fd = fopen ($img, 'rb');
           $size=filesize ($img);
           $cont = fread ($fd, $size);
           fclose ($fd);
           $encimg = base64_encode($cont);
           return $encimg;
       }
     
         $image_base64=encode_img('123.jpg'); // to encode the image
 
then convert back to image into some location
 
$img = imagecreatefromstring(base64_decode($image_base64));
    if($img != false)
    {
    imagejpeg($img, 'user_images/image.jpg');
    }


Have Dream Day

Mysql query return the count from multiple table with left join

This the MySQL query with table where home table has one to many relation with many table,
 Here is code that return the count from multiple table.


  select  h.id,h.home_name,count(n.home_id) as ncount,
count(e.home_id) as ecount,count(b.home_id) as bcount,
count(s.home_id) as scount
 from home as h left join news as n on (h.id=n.home_club_id)
left join events as e on (h.id=e.home_id)
left join billboard as b on (h.id=b.home_id)
left join store as s on(h.id=s.home_id) where 1

Have Dream Day