1

I am using PHP 5.3.5 and postgreSQL. I am storing and extracting images from database.

For storing i am doing this:

 $escaped_data = base64_encode(file_get_contents($_FILES['fileUpload']['tmp_name']));
 $fileModel->setBinary_Data($escaped_data);

It's working, i received the image in my database (Bytea field).

The problem is to extract this, i am trying this code to extract my images:

$file_info = $fileModel->getBinary_Data($id_file); // This function return the binary_data of the image

header('Content-Type: image/jpeg;base64');
header('Content-Disposition: attachment; filename=' . $file_info['_name']);
base64_decode($file_info['binary_data']));

When i download the image, i can't see the image...

With echo in:

echo base64_decode($file_info['binary_data']);

This happen:

http://imageshack.us/f/18/encodez.jpg/

After, i am trying using the function stream_get_contents inside base64_decode, but doens't work.

Someone know how i can download my images with php?

Thanks anyway...

KillCloud
  • 17
  • 5

1 Answers1

0

Well obviously your custom getBinary_Data() returns $file_info['binary_data'] as a resource, not a string.. so either change the function or use base64_decode(file_get_contents($file_info['binary_data'])));

And try to use fclose($file_info['binary_data']); too then.

P.S. Wasn't there a blob type for binary data in postgre?

Artjom Kurapov
  • 6,115
  • 4
  • 32
  • 42