raydona Posted April 22, 2009 Share Posted April 22, 2009 Hi, I’ve uploaded Microsoft Word docs to a MySql database and stored them as binary files. But when I download a file and try to display it in a browser (Firefox or IE) illegible characters are displayed. It seems that a file needs to be transformed back to a Word doc for it to be displayed correctly. Here is the PHP code for downloading a file: <?php $con = mysql_connect("hostserver",“user","pswd"); if(!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $sql = "SELECT name, type, size, content FROM CVs ". "WHERE id = 3"; $res = mysql_query($sql) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($res); header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: attachment; filename=$name"); echo $content; mysql_close($con); exit; ?> I wonder if anyone has any suggestions as to how to rectify the problem. I am completely lost as to what to do next. I would be very grateful for all help. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 22, 2009 Share Posted April 22, 2009 why are you storing that in a database? the overhead with storing files in a database is pretty big so rarely I'd do anything like that. if its a case of storing the file securely maybe look at storing it behind the site root and forcing download rather than displaying in browser... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.