Unexpected newline prepended to file
- From: "C. (http://symcbean.blogspot.com/)" <colin.mckinnon@xxxxxxxxx>
- Date: Tue, 24 Nov 2009 08:47:00 -0800 (PST)
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.
.
- Follow-Ups:
- Re: Unexpected newline prepended to file
- From: Peter H. Coffin
- Re: Unexpected newline prepended to file
- Prev by Date: Mailing list
- Next by Date: Re: Unexpected newline prepended to file
- Previous by thread: Mailing list
- Next by thread: Re: Unexpected newline prepended to file
- Index(es):
Relevant Pages
|