PHP如何打开.doc和.docx文件? [重复]

This question already has an answer here:

doc files

$filename = 'ahfdghasfdh.doc';
header('Content-type: application/msword');
header('Content-Disposition: inline; filename="testqq"');
@readfile($filename); 

I tried this code its not working. How to open the .doc files on browser using php.

</div>

Try below code.

<?php
$filename = 'ahfdghasfdh.doc';
header('Content-disposition: inline');
header('Content-type: application/msword'); // not sure if this is the correct MIME type
readfile($filename);
exit;
?>

You can open as like that:

<a href="yourfile.doc">MSWORD FILE</a>

And other solution @vinod already shared

And if you just want to open doc file on browser no application involved than I recommend to use GOOGLE DOCS.