You are not logged in.

#1 2010-07-29 13:32:17

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

[SOLVED] Problem with showing a jpeg from a mysql database with php

EDIT: I'm a dumbass.. All the time I had 'source' in my img tag instead of 'src'... Facepalm.

Hi all

For my job I'm coding a very small webapp in php, it should just have a page that takes images and stores them in a database (that part works) and another page to request images based on certain identifiers. I have written a class to get the images from the DB and it seems to work ok if I set the header as

header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");

and just echo the blob I got from mysql as

echo $imgwriter->write();

where imgwriter is an object of the class that retrieves the image and the write() function returns the blob. I can then download the file and all is fine.

What's not working, is putting the image directly in a page in an <img> tag, I tried by commenting out the last header line of above and doing

echo "<img source=\"$imgwriter->write()\" />";

This gives me a page with an icon of a broken file. I guess my browser (firefox) cannot interpret the data. Does anyone see what I'm doing wrong? All guides on google seem to do what I did and I'm really going nuts over this.

Also, I'm using PHP 4, the server this app is running on is not mine so I can't update it.

Any help is appreciated smile

Last edited by Ramses de Norre (2010-07-29 14:36:01)

Offline

Board footer

Powered by FluxBB