views:

33

answers:

2

I've uploaded an MS powerpoint file to my server, and I'm trying to use Google Docs viewer (http://docs.google.com/viewer) to display it on a webpage. The file is available here: http://elgg.wamped.org/test.ppt

If I invoke the docs viewer with the above URL, it is working as expected, see: http://docs.google.com/viewer?url=http%3A%2F%2Felgg.wamped.org%2Ftest.ppt

But when I'm trying to serve the same file through a very simple php script to the viewer, it fails rendering with the not too helpful error message: "Sorry, we are unable to generate a view of the document at this time", see: http://docs.google.com/viewer?url=http%3A%2F%2Felgg.wamped.org%2Freadfile.php

The script that serves the file is as follows:

<?php
  header('Content-type: application/vnd.ms-powerpoint');
  header('Content-Disposition: attachment; filename="test.ppt"');
  readfile('test.ppt');
?>

I've tried playing around with various header fields like Pragma and Cache-Control, but nothing helped. I also tried slicing the output file and echoing in chunks, that also did not do any good. Checked the apache log on the server, checked the response headers, everything seems fine to me.

Any ideas what am I doing wrong here?

EDIT: Although I haven't found a solution to this issue, I stumbled upon a site that does the same (or seems to do more than that, actually) as Google Docs Viewer. http://embedit.in has support for a wide range of file types, has an API, and does the job nicely, so I'll just probably go with that one. However, out of curiousity, I'd still like to know what is wrong with the piece of code below. So any suggestions are more than welcome.

A: 

It looks like you might be missing some headers. You might also want to see if the file is in the same directory as readfile.php, because google might store each file on a remote server.

Colum
I don't see how the file location on my server can be relevant for google docs. The file is served by a php script, so it can be anywhere and I just need to provide the full path for it, right? Also, any ideas what headers I might be missing? As I specifically stated in my question, I tried quite a number of fields, but nothing seemed to help.
András Szepesházi
+1  A: 

Have you tried naming the php file with a .ppt file extension instead of .php? Whether or not your server will process php code in a file that doesn't have a .php file extension is another problem. But Google Docs may simply say NO to loading any file with a .php extension on it.

Bob Foster
Bingo! Thank you very much for this. I've added a simple rewrite rule to htaccess that redirects readfile.ppt to readfile.php, and voila! ppt file shows perfectly.
András Szepesházi