Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Brainx7   Members   -  Reputation: 123

Like
0Likes
Like

Posted 07 August 2014 - 11:16 AM

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' >

 



Sponsor:

#2 SimonForsman   Crossbones+   -  Reputation: 6168

Like
1Likes
Like

Posted 07 August 2014 - 11:45 AM

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; ?>

Edited by SimonForsman, 07 August 2014 - 11:53 AM.

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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS