我正在尝试向多个收件人发送带有文件 URL 附件的邮件,但是在 postman 中点击 api 时,它会抛出错误无法打开文件进行读取 [ 文件链接 ] ,但是当我复制文件链接时,在浏览器中打开,它打开得很好。
我也检查了文件权限,并引用了 Stackoverflow 上的一些答案,但没有任何帮助,请尽快帮助我。
$file_name = 'TimeActivityReport' . "_" . time() . '.pdf';
$storage_path = 'public/TimeActivityReport';
// $storage_path = public_path();
$filePath = $storage_path . '/' . $file_name;
// return $filePath;
$exl = Excel::store(new TimeActivityReportExport($all_total_values,$data,$date_totals), $filePath);
if($exl)
{
$fileurl = asset('storage/TimeActivityReport').'/'.$file_name;
// return $fileurl;
}
// return $fileurl;
return Mail::send([], $emails, function($message)use($fileurl,$emails) {
$message->to($emails,'hello')
->subject('test')
->attach($fileurl,[
'as' => 'checkname.pdf',
'mime' => 'application/pdf'
])
->setBody('check');
});
最佳答案
试试这个,我在我这边测试了它,它返回了文件
Storage::get('./public/TimeActivityReport/'.$file_name);
您还可以使用以下方法测试文件是否存在:
Storage::disk('local')->exists('public/TimeActivityReport/'.$file_name);
要附加尝试:
$fileurl = Storage::path('public/TimeActivityReport/'.$file_name);
关于laravel - 无法打开文件进行读取 [ 文件链接 ] laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64521526/