You are here: Re: Downloaded word document not correct « PHP Programming Language « IT news, forums, messages
Re: Downloaded word document not correct

Posted by Taras_96 on 03/30/07 02:36

In case anyone runs into the same problem, the problem I was having
was caused because output buffering was turned on. Turning off output
buffering solved the problem.

Couple of questions though:

1) Why would only word documents get confused by this? I could
succesfully download PDFs with ob buffering turned on, for example.
2) I checked the buffer to see what was in it just before turning it
off. It had "\r\n\r\n" which, in HTTP, indicates that header data has
finished and what follows is actual data. Where did these characters
in the buffer come from?
3) Related to question 2. Even though the buffer had data in it prior
to sending headers, I could succesfully send headers. Usually if you
try to send headers after outputting data PHP throws an error.

On Mar 10, 4:21 pm, "Taras_96" <taras...@gmail.com> wrote:
> Hi everyone,
>
> I'm using PHP and a DB to control access to files that have been
> uploaded by users. I am using the following PHP code snippet to
> deliver the file after the access rights have been checked.
>
> $theFile = file_get_contents(UPLOAD_PATH.$storedName);
> if($mimeExtension == '')
> {
> header("Content-Type: application/octet-stream\n");
> }
> else
> {
> header("Content-Type: $mimeExtension\n");
> }
> header("Content-Disposition: attachment; filename=
> \"$documentName\"\n");
> // doesn't work with base64 or binary
> header("Content-Transfer-Encoding: binary\n");
> header("Content-length: " . strlen($theFile) . "\n");
>
> echo $theFile;
>
> Now, text files open up fine. Word documents though, especially those
> with embedded photos, come out mangled. I have tried sending the word
> document with the content type being sent to both application/octet-
> stream and the word document one. The file on the server (which is my
> computer, as I am currently developing the site) is fine. This means
> that something goes wrong while the file is being sent. I suspect the
> Content-Transfer-Encoding header, but setting it to binary (which was
> my original code) or base64 doesn't fix the problem. What could
> possible be the problem?
>
> Secondly, when the user presses 'save', the save button remains
> depressed until the document has finished uploading. It's as if the
> save operation 'blocks', rather than adding the save to the download
> manager and getting rid of the save screen. That is, the 'save as'
> screen remains visible, with the save button pressed down, until the
> file is completely downloaded. How can I avoid this?
>
> Cheers
>
> Taras

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация