I have been struggling with the following problem, and any light people can shed would be much appreciated.
I have a table which I want to store files in (I know about the pro's and con's of doing this instead of using the file system) - and am successfully able to upload all document types.
When I view the documents (word, excel, pdf etc) from MySql Browser they appear fine.
When I attempt to download them using my script, they download but then show up as binary (chars). The only document type that works successfully is pdf.
The filetype is correct in the database, and is being passed correctly in the download script (eg application/msword).
Im stuck ... does anyone have any idea? my download script is below...
function downloadDocument($document)
{
$query = "SELECT content, filename, type, size FROM documents WHERE recid=$document";
$result = mysql_query($query) or die(mysql_error());
list($content, $name, $type, $size) = mysql_fetch_array($result);
header("Content-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
header("Content-transfer-encoding: binary");
echo $content;
die();
}
Thanks