Entry
I can't display a blob variable which I store in database when I try to retrive it, can you hep me?
May 15th, 2002 05:54
Zoot Froot, Freddy Christian, gayatri krishnamurthi,
1) I wonder if you are referring to displaying an image from blob data
you have stored in the DB? If so see part 2 of this answer.
Anyway, the biggest problem I ran into with blobs was that the binary
data got screwed up while I was reading it from a file. It turned out
that while doing an fopen(),fread() or some other read/write
operations, PHP was automatically escaping some of the binary data and
thus corrupting the file. To solve the problem I manipulated
the "magic_quotes_runtime" PHP setting like so:
ini_set('magic_quotes_runtime',0);
// ### DO BINARY READ/WRITE HERE
ini_set('magic_quotes_runtime',get_magic_quotes_gpc());
After that I had no more problems. Hope this helps.
2) Displaying the blob image is a matter of writing the following kind
of page:
- Run a SELECT on the database to get the blob data and store the blob
in a variable.
- Send a Content-Type header of the correct type for your image.
e.g. header('Content-Type: image/gif');
- Echo the blob variable.
Remember you have to call this page from another page to view the image.
e.g. <IMG SRC="displayblob.php">