Page 1 of 1
Trying to download to .pages
Posted: Mon Sep 19, 2016 2:12 am
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
Re: Trying to download to .pages
Posted: Mon Sep 19, 2016 7:09 pm
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');
Re: Trying to download to .pages
Posted: Wed Sep 21, 2016 6:04 am
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]
Re: Trying to download to .pages
Posted: Wed Sep 21, 2016 6:55 am
by Celauran
So you're sending ms-word headers and XHTML content?
Re: Trying to download to .pages
Posted: Wed Sep 21, 2016 7:53 am
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.
Re: Trying to download to .pages
Posted: Wed Sep 21, 2016 2:45 pm
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
Re: Trying to download to .pages
Posted: Fri Sep 23, 2016 4:02 am
by Addos
Thank you for pointing me to all of this.