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?
Force File Open In Word
Moderator: General Moderators
-
thewebdrivers
- Forum Commoner
- Posts: 41
- Joined: Fri Aug 17, 2007 3:32 pm
- Location: india
- Contact:
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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
However, you still need to specify your $filename, which is the path to your word file.
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);