Trying to download to .pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Trying to download to .pages

Post by Addos »

Using the following PHP code to download table content into a .doc woks fine on Windows but on a Mac it give the error message. “Sorry Pages can’t open this for some reason”.

Code: Select all

<?PHP header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; Filename=blah-blah.doc”); 
?>
Tried various versions using quote's "Filename=blah-blah.doc” "

I have tried multiple ways around this including using .rtf, .pdf, .csv (.cvc works but is not usable) but none will open in Pages. I even tried converting the headers from .doc to .pages but again nothing. If I simply click on a word document it opens fine in Pages so its not a local issue as far as I can see. The content in the database is just text with nothing else and I can easily echo this to a .php page so there is something within the headers that .pages seems to need. Anyone ever dealt with this for Pages before? Nothing is coming up on the web despite a day of searching.

Thanks
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Trying to download to .pages

Post by Christopher »

You need to actually send the file in addition to the headers:

Code: Select all

<?PHP header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; Filename=blah-blah.doc”); 
readfile('/path/to/blah-blah.doc');
(#10850)
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Re: Trying to download to .pages

Post by Addos »

Hi Christopher, many thanks for taking the time to reply. I probably needed to be a little more clear in my first post. I don't actually store a .doc on the server I just create this by pulling content from the DB. This is a sample of the page I use that works on Windows/Word. So if sombody follows a link to this page it automatically downloads the document.

Any further thoughts?

Thanks again.

Code: Select all

<?php require_once('Connect-etc.php'); 
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; Filename=blah-blah.doc");?>  
[text]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">
<title>Saves as a Word Doc</title>
</head>
<body>[/text]

Code: Select all

<?php mysql_select_db($etc, $etc);
$query_GetWord = "SELECT * FROM table-etc";
$GetWord = mysql_query($query_GetWord, $etc-etc) or die(mysql_error());
$row_GetWord = mysql_fetch_assoc($GetWord);
$totalRows_GetWord = mysql_num_rows($GetWord);
echo $row_GetWord['info']; 
 ?>  
[text]</body>
</html>[/text]
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Trying to download to .pages

Post by Celauran »

So you're sending ms-word headers and XHTML content?
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Re: Trying to download to .pages

Post by Addos »

Thanks for the reply. That's just a sample of what I've tried which worked on a PC but I can't get the same result for Mac - Pages. At this stage it's getting beyond my limited knowledge of PHP. I thought this should have been a fairly simple script to just output some specific page text-content to a file similar to a PDF etc. but it looks like I'm wrong.

Thanks again.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Trying to download to .pages

Post by Christopher »

Addos wrote:Any further thoughts?
The headers tell the browser what type of document is being sent to it. To generate a Word document from data, look into classes like: https://github.com/PHPOffice
(#10850)
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Re: Trying to download to .pages

Post by Addos »

Thank you for pointing me to all of this.
Post Reply