On the LAMP stack, I cannot get xSendFile to work. The problem is that downloads have 0 bytes.
To make sure xSendFile is installed, I added this to my file .htaccess:
<IfModule mod_xsendfile.c>
SetEnv MOD_mod_xsendfile 1
</IfModule>
(I cannot verify this with apache_get_modules(), because I am running PHP as fastCGI.)
Then I have the following PHP code:
if (1 != getenv('MOD_mod_xsendfile'))
{
echo 'mod_xsendfile is not installed';
}
else
{
$path = '/home/infar/';
$file = 'hello.txt';
if (file_exists($path.$file) && strlen($path.$file)>1)
{
if (true)
{
Yii::app()->request->xSendFile($path.$file,array(
'saveName'=> 'hello.txt',
'mimeType'=> 'plain/text',
'terminate'=> true,
));
}
else
{
header('Content-Type: plain/text');
header('Content-Disposition: attachment;filename=hello.txt');
header('X-Sendfile: $path.$file');
exit;
}
}
else
{
echo 'file not found at: '.$path.$file;
}
}
This code works as expected; from which I conclude that xSendFile should be installed and / or enabled. Then I run this script with both Yii xSendFileand simple PHP. In both cases, the download window opens, but always with 0 bytes.
I am at the end of my mind. What am I doing wrong?
In the interest of full disclosure, here is the relevant part httpd.conf:
<IfModule mod_xsendfile.c>
XSendFile on
XSendFilePath /home/infar
</IfModule>
Edit:
Output compression disabled:
ini_get("zlib.output_compression"); // returns "Off"
Chrome :
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Disposition:attachment;filename=hello.txt
Content-Length:0
Content-Type:plain/text
Date:Sun, 23 Mar 2014 18:22:49 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=2, max=100
Pragma:no-cache
Server:Apache
X-Sendfile:/home/infar/hello.txt
26 2014
@gabrieloliveira :
header('Content-Type: plain/text');
header('Content-Disposition: attachment;filename=hello.txt');
header('X-Sendfile: '.$path.$file); // $path.$file outside quotes
header('Content-Length: '.filesize($path.$file)); // Filesize
echo '12345678901234567890';
exit;
script ( echo '12345678901234567890';) , 16- 1234567890123456. 16 hello.txt. ,
- - .
- X-SendFile , :
- X-SendFile .
, X-SendFile, :
// header('X-Sendfile: '.$path.$file);
; X-Sendfile.