to show the doc file in web pages

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robin1983
    New Member
    • Oct 2007
    • 99

    to show the doc file in web pages

    Hi guys, I have a data base to store some .doc file and actually i give a link in one of pages. When i click the link, i wan to show the content of the doc file in the webpages. the code is given below
    [PHP]<a href="file.php? id=<?php echo $row['id']; ?>" target="new window">File</a>[/PHP]

    and the the file.php is given below
    [PHP]
    <?php
    include "config.inc.php ";
    include "connect.inc.ph p";

    if(isset($_GET['id']))
    {
    $id = $_GET['id'];
    $query = "SELECT filename, filetype, filesize, content FROM candidate_table where id = '$id'";
    $result = mysql_query($qu ery) or die(mysql_error ());

    list($name, $type, $size, $content) = mysql_fetch_arr ay($result);

    echo "<div style=\"border: 1px blue solid; \">";
    echo $content;
    echo "</div>";
    /*
    header("Content-length:$size");
    header("Content-type:$type");
    header("Content-Disposition:att achment; $filename=$name ");
    echo $content;*/
    exit;
    }

    ?>

    [/PHP]

    But the problem is that, when i click, it working but the content showing in the web pages is not like wat i submitted.
    it shwing some thing like this too
    [HTML]
    m’¾oµ¶Á ù)HIkƒ„ “¬Áá!; <=ýýýýýýýýøøø øøýýýýýýýýýýýýý  & F=ý 1h°Ð/ °à=!°"°# $ %°ÇDÐÉêyùºÎŒ‚ ªK© engr@habsons .netàÉêyùºÎŒ‚ª K© 0mailto:engr@ha bsons.net i8@ñÿ8 NormalCJ_H aJmH sH tH *B*phÿ=ÿ ÿÿÿ m’¾oµ¶Áù )HIkƒ„“¬ Áá!;<? ˜0€€˜0€€˜0€€˜0€ €˜0€€˜0€€˜0€€˜0 €€˜ 0€€˜ 0€€˜ 0€€˜ 0€€˜ 0€€˜0€€˜0€€˜0€ €˜0€€˜0€€˜0€€˜0 €€˜0€€˜0€€˜0€€˜ 0€€˜0€€˜0€€= ==4[l=Xÿ„?? ÿÿjobsupdC: \Documents and Settings\jobsup 1\Application Data\Microsoft\ Word\AutoRecove ry save of Document1.asdj obsup6C:\Docume nts and Settings\jobsup 1\Desktop\Dear Mr.docv)c”fÞÈ ÿÿÿÿÿÿÿÿ ÿ„8„0 ýÆ8^„8`„0 ýo
    [/HTML]
    I want to know how to show the exact content in the web pages,
    plz guide me .. thanks
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi Robin.

    The problem is not with your code. It is doing exactly what it is supposed to do.
    The problem is that the contents of a .doc file is not text.

    If you want to display the text found inside a .doc file, you will have to get a .doc parser and parse the file into plain text. I'm afraid I do not know of any .doc parser, but that would be the best bet.

    You could always send the file as a .doc file, in the hope that your users browser will be able to understand it. If your users have M$ Office on their computers, odds are that their browsers will be able to display it.

    To try that, set the Content-Type header of the response and then echo the contents of the document.
    [code=php]
    header("Content-Type: application/msword");
    echo $fileContents;
    [/code]

    Comment

    • dignat
      New Member
      • Aug 2011
      • 3

      #3
      hello Attli, I have the sane problem \i can not read properly word document. I ma using the content-type: application/msword, but it is not working

      Comment

      Working...