Forum Stats

  • 3,827,142 Users
  • 2,260,745 Discussions
  • 7,897,182 Comments

Discussions

Fetch Blob image from database and save in file

Hassan Mahmood
Hassan Mahmood Member Posts: 1
edited Nov 24, 2014 2:35PM in PHP

Hi,

I am using the following code to fetch a picture stored in database (blob type)

$sql = "SELECT PICTURE FROM NEW_PICT WHERE SR_NO = 1";

$stid = oci_parse($conn, $sql);

oci_execute($stid);

if(OCIFetch($stid)) //if file exists

{

$a=OCIResult($stid,"PICTURE");

}

file_put_contents('pics/test.jpg', $a->load());

The code works fine with no errors and it generate the picture "test.jpg". The image also opens in windows image viewer.

But when I try to open this image with Photoshop or any other image editing tool, the error occur "Invalid JPEG Marker" or "Invalid File Type"

Also the image dose not display in browser.

Please help.

Thanks

Answers

This discussion has been closed.