[php/mysql] upload -> download, 1 or 2 extra bytes???

wxdqz

New Member
Hi,

I have a mysql database in which i'd like to upload files (images, pdf's, word docs etc). I store them in a longblob file using the code:

$dataToSave = addslashes(fread(fopen($fileToSave, $fileSize)));

When I "download" from the database, I can save the file and it gets a filesize which is two bytes larger than the original!?

Using hexedit I've seen that two bytes are appended to the file, namely 0x20 and 0x0A (space and -i think- linefeed).

Then I try to remove the two using the following code:

first I send the header with the appropriate filetype (application/pdf for instance) then I echo the contents of the longblob by:

echo rtrim($var, "\0x0A..0x20"); but this removes only the 0x20 byte, not the 0x0A byte.

This byte has to be removed though, because otherwise word, acrobat etc. can't read the file properly.

Anyone with insight on how to solve this mysterious behaviour?
 
Top