php problem,how to make download button not show on word document

Started by
0 comments, last by SimonForsman 9 years, 9 months ago

I have a php website, that when you click download as ms word, it downloads the page as a ms word document, the only proplem I have is that the button is showing in the word document, how can I make it not show on the word document.

the php code to make the word document when I click download is

if(isset($_POST['submit_docs']))
{
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=word.doc");
}

the html code is

<input type='submit' class='no-print' value= 'Download as MS word' name= 'submit_docs' >

Advertisement

I have a php website, that when you click download as ms word, it downloads the page as a ms word document, the only proplem I have is that the button is showing in the word document, how can I make it not show on the word document.

the php code to make the word document when I click download is

if(isset($_POST['submit_docs']))
{
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=word.doc");
}

the html code is

<input type='submit' class='no-print' value= 'Download as MS word' name= 'submit_docs' >


First of all. You are not downloading a word document, you are giving a html document a .doc extension and changing the content-type header to trick the clients browser into downloading(or open with a document plugin) instead of displaying the document normally. (This is incredibly bad practice, there is no guarantee that future versions of MS-Word or competing wordprocessors will read those files correctly).

You should grab PHPDocX(The community version is free): http://phpdocx.com
or PHPWord : phpword.codeplex.com
to generate properly formed word documents instead.

If you absolutely insist on sending .html files to the user with an incorrect file extension http headers to trick the clients OS and/or browser into launching a potentially incompatible program/plugin to open it you can set a variable after you've set the headers: i.e $skip_buttons = true; and then just do a check before the markup for the button:

<?php if(!$skip_buttons): ?>
<input ..../>
<?php endif; ?>
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

This topic is closed to new replies.

Advertisement