php - Dynamic file names with Apache mod_header and file downloads using Content-Disposition -


i have bad problem on site file downloads getting truncated when use php set content-disposition "attachment" , sending file using readfile(). know of notorious problem since there plenty of discussion on php's readfile() manual page. have tried each of solutions posted there no luck (sending chunked output, disabling gzip compression in both apache/php). here gist of code, without workarounds, you'd find on 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)); ob_clean(); flush(); readfile($file); 

most importantly, notice i'd able send dynamic file name browser, avoid more machine-friendly codes use store files on disk. , yes, have done plenty of security checks before bit of code executes -- know readfile() can security flaw. :-)

the reliable way have found send complete file trash php , instead use apache's mod_header force file download. so:

<filesmatch "\.mp4$">   forcetype application/octet-stream   header set content-disposition attachment </filesmatch> 

this works well, there's big problem -- can no longer generate dynamic file names upon request, important content. know specifying ;filename=file_name.mp4, remember - need specify dynamic name rather file_name.mp4.

it nice if somehow notify apache (using php) of dynamic file name when sending file. possible? or going forced rename files on disk user-friendly name? php solutions aren't working @ all. files 15mb, , truncated less 2mb when transferring. ouch!

help me stack overflow kenobi! you're hope.

try mod_xsendfile described here. allows php step out of middle of http conversation @ point php sets x-sendfile header - but, can see on blog, allows setting content-disposition header.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -