0

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.

Vinod Patidar
  • 685
  • 4
  • 17
Dinesh Kumar
  • 353
  • 7
  • 16
  • The `@` you're using suppresses error messages if `readfile` throws an error. It's obviously unhelpful to suppress error messages when you're trying to debug code that isn't working. Remove the `@` and check what errors you get. – Mark Amery Dec 27 '15 at 13:30

2 Answers2

0

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;
?>
Vinod Patidar
  • 685
  • 4
  • 17
0

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.

devpro
  • 16,184
  • 3
  • 27
  • 38