• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

PHP/MySQL Question - Office documents and the BLOB datatype

Are any special headers needed in storing MS Office documents in a blob datatype in mySQL?

My script works for non-Office docs (tested with PDF and plain-text), but not Word, Powerpoint, or Excel files. When downloading these types, I get a bunch of messed up characters in the beginning. yet the same script downloads PDF's and plain text files fine.

This is my download script:

$fid = $_GET['fid'];
$result = mysql_query("SELECT * from files WHERE fid =" . $fid, $db);

$file = mysql_result($result, 0, "file");
$fname = mysql_result($result, 0, "fname");
$fsize = mysql_result($result, 0, "fsize");
$ftype = mysql_result($result, 0, "ftype");

header("Content-type: $ftype");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$fname");
header("Content-Length: $fsize");
echo $file;

edit: just tested this with *.au and *wav audio, and they don't work either. grrr whats going on here...
 
Well I took out most the other code on that page and now files download fine only if i save to disk. if i try to open it up in an IE window, its still messed. any one else have ideas?
 
i made a similar thing that worksfor anything... the only thing i can can remember is to be sure and escape the string as it is going in. also, ensure that you're using a large blob (regular blob is limited to 64K i believe)

let us know your results
 
i'm already using the mediumblob type, which handles up to 16MB. I'm confused as hell as to why everything works when i save the file, but completely messes up when i try to open.
 
Originally posted by: notfred
Originally posted by: toekramp
gotta set the right MIME type


This is the correct answer, although I don't know the proper MIME types for MS Office files.

MIME-types were set (these were inherited when the file was uploaded so shoulda been good), I actually fixed the problem, or rather the combination of problems.

First off, I had some erroneous spaces printed on the page, which I guess was screwing it up. Second off, I didn't know that MS Office documents had to be fully cached to open correctly, I had caching off to force a fresh download from the server, however this apparently worked with text files and PDF's, but didn't play well with Office docs and multimedia.

I set the http cache-control to private and removed those gd spaces, and it works flawlessly now.

edit: mime types for some office docs, if anyone cares or wanted to know:

word: application/msword
excel: application/vnd.ms-excel
powerpoint: application/vnd.ms-powerpoint
 
What I found to be effective is just to store the mime type as sent when uploading the file. this makes it easy enough that you don't have to store a reference to them

here's a few in a db of mine atm:

application/msword
application/vnd.visio
application/octet-stream
application/vnd.visio
application/octet-stream
application/vnd.visio
application/vnd.visio
application/vnd.visio
application/x-zip-compressed
 
Originally posted by: eklass
What I found to be effective is just to store the mime type as sent when uploading the file. this makes it easy enough that you don't have to store a reference to them

here's a few in a db of mine atm:

application/msword
application/vnd.visio
application/octet-stream
application/vnd.visio
application/octet-stream
application/vnd.visio
application/vnd.visio
application/vnd.visio
application/x-zip-compressed


if you read the thread carefully, you'd eralize i had done this from the start 🙂
 
Back
Top