我已经下载了像
这样的aws urlhttps://xxx-xx-dev.s3.ap-south-1.amazonaws.com/std_check/6557122022151745398XtquBSY.pdf
当这个url放到ifrem中时,文件会自动下载,而不是在引导模型中下载视图。我的代码在这里,
查看文件
function PDFOPEN(path) {
$.ajax({
type: 'post',
url: '{{ route('background.pdf.show') }}',
data: {
"_token": "{{ csrf_token() }}",
'path':path
},
success: function(data) {
if (data.status == true) {
} else {
toastr.error(data.message);
}
}
});
}
Controller File is
public function BackgroundVerifyShow(Request $request)
{
$file = Storage::disk('s3')->url($request->path);
header('Content-Type: application/pdf');
header(sprintf("Content-disposition: inline;filename=%s", basename($file)));
@readfile($file);
}
那么,如何读取这个文件在ajax成功后启动模型
readfile
函数将返回true
或false
。
public function BackgroundVerifyShow(Request $request)
{
$file = Storage::disk('s3')->url($request->path);
header('Content-Type: application/pdf');
header(sprintf("Content-disposition: inline;filename=%s", basename($file)));
header("Content-Type: " . $asset->mime);
echo json_encode({status => readfile($file)});
}