Jump to content

Cannot display word doc in browser


raydona

Recommended Posts

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.

 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.