Page 1 of 1

Force File Open In Word

Posted: Tue Aug 28, 2007 12:36 pm
by icesolid
I am having an issue with linking to Word documents on my site.

I would like to have every users computer open the Word doc in Word when they click on an link to a Word document on my site.

However, some users browsers open the document right up in the browser, some lag and take a real long time to open the document and some do exactly as a like and open right up in Word.

I know that this is a setting in the users browser, however is there anyway to force this behavior from my PHP or JavaScript code?

Any suggestions?

Posted: Tue Aug 28, 2007 1:20 pm
by thewebdrivers
mmmm.... i don't really think there is anything that can be done.

Posted: Tue Aug 28, 2007 1:35 pm
by John Cartwright
What you'll need to do is create a php script to handle file downloads.

From our useful posts thread, viewtopic.php?p=53557#53557

Code: Select all

$file = fopen($filename, 'r');

//set some HTTP headers
Header('Content-Type: application/x-octet-stream');
Header('Content-Transfer-Encoding: binary');
Header('Content-Length: ' . filesize($filename));
Header('Cache-Control: no-cache, must-revalidate'); //HTTP 1.1
Header('Cache-Control: post-check=0, pre-check=0', false); //HTTP 1.1
Header('Pragma: no-cache'); //HTTP 1.0
Header('Content-Description: Whatever the file is');
Header('Content-Disposition: attachment; filename="'.$filename.'"');
Header('Title: ' .$filename());

while(!$feof($file))
     print(fread($file, 4096));

fclose($file);
However, you still need to specify your $filename, which is the path to your word file.