Domanda

I have a program with images stored as blobs in a MySQL database, and it works perfectly except for my download link. It downloads just as it should, and is the right size as well, but the images doesn't show.

While uploading this is mainly how the image is handled:

$image = $_FILES['image']['tmp_name'];

$data = file_get_contents($image);

Then I'm using PDO for MySQL connection:

$q->bindParam(2, $data, PDO::PARAM_LOB);

This works fine when using base64.

$image = new Gmagick();
$image->readimageblob($data);
<img src="data:image/'.$ext.';base64,'.base64_encode($image->getimageblob()).'" />';

But here is my problem.

header('Content-Disposition: attachment; filename='.$regnr.'-'.$id.'.'.$ext;
header("Content-type: image/$ext");
header("Content-length: $size");
echo $data; 

I have also tried to echo $image->getimageblob(); and such... as well as some other headers. But the result is the same, the image downloads, is the correct size and format, but I can't read it.

How do I solve this?

È stato utile?

Soluzione

I found the answer. I think I used about 15 hours on this..

Although, if anyone is wondering, the solution is one simple line:

 ob_clean();

before output.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top