[英]Force download .xls file in Laravel 4.2
I have the following route: 我有以下路线:
Route::get('/download/{id}/{filename}', function($id, $filename)
{
// Check if file exists in app/storage/file folder
$file_path = storage_path() .'/orders/'.'/'.$id.'/'. $filename;
if (file_exists($file_path))
{
// Send Download
return Response::download($file_path, $filename, [
'Content-Type: application/vnd.ms-excel; charset=utf-8'
]);
}
else
{
// Error
exit('Requested file does not exist on our server!');
}
})->where('filename', '[A-Za-z0-9\-\_\.]+');
That downloads an excel file form /app/storage in Laravel (previously uploaded). 那会在Laravel中下载一个excel文件格式/ app / storage(先前已上传)。 The problem I'm facing is that the downloaded excel file is unreadable by excel.
我面临的问题是Excel无法读取下载的Excel文件。 If I download the uploaded file from FTP it's ok.
如果我从FTP下载上载的文件就可以了。 I tried all types of headers for Content-Type but nothing seems to work.
我尝试了所有类型的Content-Type标头,但似乎无济于事。 Is there a special header for excel files?
excel文件有特殊的标题吗? Thanks a lot.
非常感谢。
i am using this code in CI please find helper file or library for Laravel 我在CI中使用此代码,请找到Laravel的帮助文件或库
$this->load->helper('download');
if(file_exists("user_files/test.txt")){
$data = file_get_contents("user_files/test.txt");
force_download("test.txt", $data);
}else{
echo "Error";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.