I have used the following code before uploading an image into mysql database
Before encoding I have also done
$content = addslashes($content);
$content = base64_encode($content);
Then after that I have tested the image in database it was entered fine.
But, whenever I try to download the same image it saves is well on the filesystem but never let me view it. As, it give me incorrect image file. Why is it so?
$file_data= $this->get_attachment($id);
$content = $file_data['content'];
$content = stripslashes($content);
$content = base64_decode();
header("Content-length: ". strlen($content));
header("Content-type: ".$file_data['filetype']);
header("Content-Disposition: attachment; filename=".$file_data['filename']);
echo $content;
You are sending the file length of the base64 encoded string
$file_data['content']Instead, send the length of the decoded$content.