0
以下腳本是我用來強制下載的。ForceDownload中的文件大小問題
// grab the requested file's name
$file_name = $_GET['file'];
// make sure it's a file before doing anything!
if(is_file($file_name)) {
/*
Do any processing you'd like here:
1. Increment a counter
2. Do something with the DB
3. Check user permissions
4. Anything you want!
*/
// required for IE
if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); }
// get the file mime type using the file extension
switch(strtolower(substr(strrchr($file_name, '.'), 1))) {
case 'pdf': $mime = 'application/pdf'; break;
case 'zip': $mime = 'application/zip'; break;
case 'jpeg':
case 'jpg': $mime = 'image/jpg'; break;
default: $mime = 'application/force-download';
}
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($file_name)).' GMT');
header('Cache-Control: private',false);
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($file_name)); // provide file size
header('Connection: close');
readfile($file_name); // push it out
exit();
}
的問題是,上面的代碼正常工作時間少於100MB文件,它不能工作,例如用於文件了超過200MB,並說下載177個字節。
我該如何擺脫這個問題?
編輯1:
主要腳本是從here複製。
謝謝!
有一條線關於最大上傳大小的php.ini文件。將其改爲任何你想要的。這應該可以解決你的問題。 'upload_max_filesize = 20M'例如 –
除了之前的評論:請確保您的post_max_size也正確對齊。 –
我不明白上面的代碼與上傳有什麼關係? – BenLanc