【发布时间】:2016-08-17 21:47:30
【问题描述】:
我想在 laravel 5 中使用 ajax 从公共文件夹下载文件 我的 ajax 是
$.ajax({
url:'{{ url() }}/FileManager/downloadfile',
type:'post',
data:{file_name:tableData[0],dir_path:selected_row.attr('dir'),is_cloud:tableData[2]},
success:function(response) {
console.log("success");
},
error:function(e) {
console.log("error");
}
});
我的控制器方法是
public function postDownloadfile(Request $request)
{
$file_path = public_path().'/'.$request->dir_path.$request->file_name;
$download_link = link_to_asset($file_path);
return $download_link;
$file = FileDB::where("title",$request->file_name)->first();
$fileType = mime_content_type($file_path);
$headers = array('Content-Type:'. $fileType,);
return response()->download($file_path);
}
但是结果是成功但是没有下载文件
【问题讨论】: