title: Cannot convert blob to image
body: <p>I have a database where images are saved as blob. Now, I want to convert this blob data into image files.</p>
  
  <p>So I have made this code, but its not giving any result</p>
  
  <pre><code>$sql_icon = "SELECT $off_table.icon,$off_table.id
              FROM $off_table,$cnt_table,$ctg_table
              WHERE  $off_table.id = $cnt_table.id
              AND $off_table.id = $ctg_table.id
              AND ".$cond_api."
              AND ".$cond_nt."
              AND ".$cond_cnt."
              AND ".$cond_ctg;
  
  
  $result_icon = mysql_query($sql_icon);
  
  while($row = mysql_fetch_array($result_icon)) 
      {
         $image = $row["icon"];
         $id = $row["id"];
  
         $file = fopen("./image/".$id.".jpg","w");
         fwrite($file, base64_decode($image));
         fclose($file);
      }
  </code></pre>
  
  <p>The issue is, I am getting files but no extensions and if I rename them to ".jpg" extension, then its displaying "no preview available"</p>
  
  <p>NOTE:</p>
  
  <p>The images are saved into database by this method</p>
  
  <pre><code>$sql = "INSERT INTO aw_offers_v2
                      (
                      id,name,description,payout_type,
                      payout,expiration_date,creation_date,preview_url,
                      tracking_url,categories,countries,countries_short,
                      api_key,network_id, icon,icon_size)
                      VALUES
                      ('$id','$name','$description','$payout_type',
                      '$payout','$expiration_time','$creation_time','$preview_url',
                      '$tracking_url','$categories','$countries','$countries_short',
                      '$api','$api_url','".mysql_real_escape_string(file_get_contents($cover_image_src))."','".strlen(file_get_contents($cover_image_src))."')";
  </code></pre>
  
  <p>If I write this code</p>
  
  <pre><code>echo '&lt;img src="data:image/jpeg;base64,'. base64_encode($image).'" /&gt;';
  </code></pre>
  
  <p>then I can see the images properly. That means the images are successfully saved.</p>
  
  <p>But I can't store them in folder as files.</p>