Re: Unexpected newline prepended to file



On Tue, 24 Nov 2009 08:47:00 -0800 (PST), C. (http://symcbean.blogspot.com/) wrote:
Hi all,

This is doing my head in!

I've got what should be a very simple script to download a file.
Actually it does lots of other things - but I can replicate the
behaviour easily using this:

<?php
header("Cache-Control: max-age=30, must-revalidate");
header("Content-Disposition: attachment; filename=
\"test.doc\"");
header("Content-Type: application/msword");
print file_get_contents('/home/colinm/msword.doc');
?>

However, MS Word reports that it is not a doc file and says I need to
install a filter. The original file IS a msword document, but the file
is somehow getting prepended with a newline character on its journey.

Which newline character? LF, CR, CRLF? What do you edit your PHP on? Is
there a line-ending on the line with ?> on it? (There shouldn't be,
FWIW. Some things will work with stuff after the > but it's not a good
idea. Make sure the cursor doesn't go anyplace after > .)

--
I still want a phone with caller-IQ.
-- Tanuki in the monastery
.



Relevant Pages

  • Re: [PHP] File download problem
    ... I think I found the problem here: The php file was saved with UTF-8 encoding, and for some unknown reason it was adding the UTF-8 BOM to the output as well. ... Why do I get those three extra bytes at the beginning of each file I download with my script? ...
    (php.general)
  • Re: Hide the file url to download
    ... >> I need to make a script in PHP to hide the url of a file. ... >> will register. ... > If people can download your file, then it's trivial for them to get to ...
    (alt.php)
  • download script problem
    ... Having the need to make some videos available for download from my website, ... some time ago I created a script by putting together some snippets from ... besides it names the file wrongly (with the name of the .php ...
    (alt.php)
  • Re: [PHP] File download problem
    ... Why do I get those three extra bytes at the beginning of each file I download with my script? ... [PHP] ... The files name, type, and size are stored in a MySQL Database. ...
    (php.general)
  • PHP SCRIPT
    ... php classified script ... guestbook ardguest free php guestbook script ... php file upload script ...
    (sci.chem.labware)