Upload and display images stored in innoDB table (BLOB Type)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Upload and display images stored in innoDB table (BLOB Type)

Post by amir »

Hi,

I'm Trying to upload and display images stored in an innoDB table (BLOB Type)

I can do it with on a MYISAM table, but I tried to do it with on an INNODB table, and it doesn't work!

Here's the PHP code I use to display the image :

<code>
... database connection and recordset ...

header("Pragma: no-cache");
header("Content-type: " . $row_rsBlob['logoType']); // image/gif
echo (($row_rsBlob['logo'])); // the binary data
</code>

I get the following message (Firefox) : The image "http://www.mydomain.com/displayImage.php" could not be displayed because it contains errors (translated from french)

Of course, I'v tried with several images and (I repeat), I'v already done it on a MYISAM table (the only difference I noticed) and it was OK

Here's the PHP code and SQL query I use to upload the file in the database:

<code>
...
$id = $_GET['id'];
$myImgData = addslashes(fread(fopen($formFile, "rb"), filesize($formFile)));

$updateSQL = "UPDATE myTable SET myTable.logo='$myImgData', myTable.logoType='$formFile_type' WHERE id=".$id;
...
</code>

Thanks for your help, I'm loosing time and the deadline is coming soon...
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

When you get
FireFox wrote:The image "http://www.mydomain.com/displayImage.php" could not be displayed because it contains errors
View the source and see if there aren't any error or extra characters at the start.
Post Reply