Jump to content

[SOLVED] Image stored in MySQL: corrupted when viewing


Loomy

Recommended Posts

I'm using MySQL to store a bunch of images (BLOB fields). Putting them in is  (I think), but when I'm trying to view any of the images again the colors (on JPEG images) is completely wrong and there's a lot of corruption - the image is beyond recognition. On PNG images there's simply a message saying the image contains errors and can not be displayed.

Here's the relevant parts of the code:
[code]
<?php

// Get data from upload form then insert the image to DB
$file_contents = addslashes(file_get_contents($file['tmp_name']));

//...

$query = "INSERT INTO `multimedia` (`data`) VALUES('$data')";


// Get image from DB and display it
header("Content-type: image/jpeg");

// $imgData = image data SELECTed from DB

echo stripslashes($imgData);

?>[/code]
(ignore the fact that there are several different variable names - this code is split among a few files)

Does anyone spot any errors, og have any idea what the cause may be? Could database charset, file charset and that sort of thing have anything to do with this?


[b]UPDATE[/b]
I solved it by removing stripslashes() - I have no idea why, but as long as it's working... :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.