Unexpected newline prepended to file



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.

All the headers are getting sent correctly:

GET /opstatsgraph/test.php HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel, application/
vnd.ms-powerpoint, application/msword, application/x-silverlight,
application/x-silverlight-2-b2, */*
Accept-Language: en-gb
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1; .NET CLR 2.0.50727)
Host: dev-sensor.slc.co.uk
Connection: Keep-Alive

HTTP/1.1 200 OK
Date: Tue, 24 Nov 2009 16:24:49 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.1.6
Cache-Control: max-age=30, must-revalidate
Content-Disposition: attachment; filename="test.doc"
Content-Length: 0
Connection: close
Content-Type: application/msword

Can anyone see what I'm doing wrong?

Oddly if I just do this:

<?php
header('Content-Type: application/msword');
print file_get_contents('/home/colinm/msword.doc');
?>

Then the MSWord file opens as expected, however I need to force the
download box to rpevent MSIE from viewing the file in the browser
window.

TIA

C.
.



Relevant Pages

  • header()
    ... I have software catalog site. ... to php script which increment download value in database and then I want ... Therefore I put to script meta "refresh" with URL to ... I write meta "refresh" not to head of first script but to begin of file. ...
    (comp.lang.php)
  • Re: Problem with ASP on Webserver
    ... No, I know the memory model, I have made my own Virtual memory dump program ... function in the script ... (Accept-Language:) ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Problem with ASP on Webserver
    ... There is no ActiveX object involved in this problem, we only request a ASP ... function in the script ... (Accept-Language:) ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Problem with ASP on Webserver
    ... There is no ActiveX object involved in this problem, we only request a ASP ... function in the script ... (Accept-Language:) ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Problem with ASP on Webserver
    ... Entrek's TOOLBOX is a lot better for memory stuff. ... function in the script ... (Accept-Language:) ...
    (microsoft.public.windowsce.platbuilder)