wintersilke Posted January 7, 2010 Share Posted January 7, 2010 I've got a webpage that has a downloadable .doc with some VBA code in it. When the link is clicked, the user's browser tries to open the doc file embedded in the browser, fails because of the VBA code, and then opens the file in MSWord. I would like to make this process more seamless and have come to understand that there a combination of html code and php code that will can force the user's local computer open the server saved word document using MS Word. I originally used this code from another forum but was unable to get it to work. I substituted my server file link in the html code as the target. Now, when the link is clicked, the php file is opened up as a txt file within the browser. Any help would be appriciated. create a downloadword.php file <? if($_GET["dwn"]) { // ob_clean(); // emptying the buffer (v >= 4.2) // Dialog for the download header("content-type: application/octet-stream"); // only for application type: application/octet-stream ! header("Content-Disposition: attachment; filename=".$_GET["dwn"]); // open with MSWord header("content-type: application/msword"); // open with MSExcel // header("content-type: application/vnd.ms-excel"); // open with text // header("content-type: text/plain"); flush(); // send the buffer readfile($_GET["dwn"]); // send the file }?> Check or Uncheck the commented lines, depending on what type of file you use. (word, excel, or other) In your HTML file : <A href="downloadword.php?dwn=yourfile.doc">Test</A> Change yourfile.word with the correct file. Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 7, 2010 Share Posted January 7, 2010 Do you have php available on your server? Quote Link to comment Share on other sites More sharing options...
ignace Posted January 7, 2010 Share Posted January 7, 2010 // Dialog for the download header("content-type: application/octet-stream"); // open with MSWord header("content-type: application/msword"); // open with MSExcel // header("content-type: application/vnd.ms-excel"); // open with text // header("content-type: text/plain"); This basically replaces content-type with: application/octet-stream then rechanges it to application/msword until it finally ends up with text/plain. You can only define one content-type Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 7, 2010 Share Posted January 7, 2010 This basically replaces content-type with: application/octet-stream then rechanges it to application/msword until it finally ends up with text/plain. You can only define one content-type Probably a piece of code given as an example somewhere else Anyway, wintersilke if you do have PHP available, first try changing <? to <?php and see if the script runs this time instead of being downloaded. Quote Link to comment Share on other sites More sharing options...
wintersilke Posted January 7, 2010 Author Share Posted January 7, 2010 It is not working...and yes it was a piece of code that I copied from elsewhere that was suppose to do what I wanted to happen.... Its very odd....this html code is basically downloading the php code and displaying it as plain text in the browser... href=3D"http://............/downloadword.= php?dwn=3D\\myserver\...............\Con= ductivity_Request.doc">Online=20 Request Form;</A><A=20 Forgive me if I do not display the entire addresses. I realize that anyone can see what I write here. Does anyone see anything wrong with what I have here? Quote Link to comment Share on other sites More sharing options...
wintersilke Posted January 7, 2010 Author Share Posted January 7, 2010 I just learned that if you are prompted to download the php file, that means that php is not running on that server so this solution to my problem is not going to work at the moment. I guess that means a java solution of some sort. Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 7, 2010 Share Posted January 7, 2010 You probably mean JavaScript. It won't help as far as I know. Quote Link to comment Share on other sites More sharing options...
haku Posted January 8, 2010 Share Posted January 8, 2010 That's right, it won't. Javascript can't do what you want. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.