问题
I'm trying to create a script that pulls an image out of the database and displays it to the user, called by <img src="viewImage/someImageName">
But the problem I'm having is when the image is displayed all of the Nulls (0x00) are replaced by 0x20 and I have no idea why. The data in the database shows it being nulls but somewhere along the way it gets changed to 0x20s.
Does anyone have any idea? is there something I'm missing?
Here is the code I'm using:
$data = $this->Image->read(NULL, $userId);
header("Content-Type: image/jpeg");
echo($data['image']);
die;
I don't think it has anything to do with the code because as you can see there is no place for error. I can dump the binary contents out and it has not yet been tampered.
Something with the stack or cakephp any thoughts?
Update: I've noticed that a space is making to the beginning of stream, I'm trying to track it down, could this be the problem?
回答1:
Yeah, something along the way is freaking out (because OMG nulls, what if something thinks they're string terminators) and replacing them with spaces. I suspect CakePHP but am not quite certain enough to say j'accuse. Try:
header('Transfer-Encoding-Type: base64');
and see if that convinces whatever's doing it to leave your data alone.
回答2:
I had a stray space in a file somewhere, lots of fun to track down :) I guess this switches the mode of something in the stack and corrupts the files
来源:https://stackoverflow.com/questions/1434943/lamp-cakephp-streaming-an-image-binary-0x00-replaced-by-0x20