【发布时间】:2013-04-03 06:39:03
【问题描述】:
我的文件(126 MB 大小,.exe)出现问题。
我使用的是标准的 laravel 下载方式。
我尝试增加内存,但它仍然提示我内存不足,或者我下载了 0 KB 大小的文件。
文档没有提到任何关于大文件大小的内容。
我的代码是
ini_set("memory_limit","-1"); // Trying to see if this works
return Response::download($full_path);
我做错了什么?
-- 编辑--
继续 Phill Sparks 评论,这就是我所拥有的并且 它有效。 它是 Phill 和一些来自 php.net 的组合。 不知道里面有没有遗漏?
public static function big_download($path, $name = null, array $headers = array())
{
if (is_null($name)) $name = basename($path);
// Prepare the headers
$headers = array_merge(array(
'Content-Description' => 'File Transfer',
'Content-Type' => File::mime(File::extension($path)),
'Content-Transfer-Encoding' => 'binary',
'Expires' => 0,
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
'Pragma' => 'public',
'Content-Length' => File::size($path),
), $headers);
$response = new Response('', 200, $headers);
$response->header('Content-Disposition', $response->disposition($name));
// If there's a session we should save it now
if (Config::get('session.driver') !== '')
{
Session::save();
}
// Below is from http://uk1.php.net/manual/en/function.fpassthru.php comments
session_write_close();
ob_end_clean();
$response->send_headers();
if ($file = fopen($path, 'rb')) {
while(!feof($file) and (connection_status()==0)) {
print(fread($file, 1024*8));
flush();
}
fclose($file);
}
// Finish off, like Laravel would
Event::fire('laravel.done', array($response));
$response->foundation->finish();
exit;
}
【问题讨论】: