I've got a bad problem on my small site where my file downloads are becoming cut down after i use PHP to create this content-Disposition to "attachment" after which delivering the file using readfile(). I understand this really is a bit of a well known problem since there's lots of discussion about this on PHP's readfile() manual page. I've attempted each one of the solutions published there without any luck (delivering chunked output, crippling gzip compression both in Apache/PHP). This is actually the gist of this code, without all of the workarounds, just like you'd think it is around the PHP manual:

$file = '/path/to/ugly.file.name.mp4';
$filename = 'ANiceFileName.mp4';
header('Content-Description: File Transfer');
header('Content-Type: video/mp4');
header('Content-Disposition: attachment; filename='.$filename.'.mp4');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));

Most significantly, observe that Let me have the ability to send an engaged file title towards the browser, to prevent the greater machine-friendly codes I personally use to keep the files on disk. Company, I've done lots of security inspections before little bit of code executes -- I know readfile() could be a security flaw. :-)

The only real reliable way I've discovered to transmit an entire file would be to simply trash PHP and rather use Apache's mod_header to pressure the file like a download. Like so:

<FilesMatch "\.mp4$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment

This is effective, there is however a large problem -- I'm able to no more generate dynamic file names upon request, that is somewhat vital that you my content. I know about indicating ;filename=file_name.mp4, but don't forget - I have to specify an engaged title as opposed to just file_name.mp4.

It might be great basically could in some way inform Apache (using PHP) from the dynamic file title when delivering personal files. Is the fact that possible? Or can i have to relabel my files on disk to some user-friendly title? The PHP solutions just aren't working whatsoever. My files are occasionally as much as 15MB, and individuals are frequently cut down to under 2MB when moving. Ouch!

Assist me to Stack Overflow Kenobi! You are my hope.

Could it be getting cut down since the php script occasions out? set_time_limit?

Try mod_xsendfile as referred to here. This essentially enables PHP to leave the center of the HTTP conversation at the reality that PHP sets the X-Sendfile header - but, as you can tell on that blog, it enables for setting your articles-Disposition header.