laravel - 无法打开文件进行读取 [ 文件链接 ] laravel

标签 laravel laravel-mail

我正在尝试向多个收件人发送带有文件 URL 附件的邮件,但是在 postman 中点击 api 时,它会抛出错误无法打开文件进行读取 [ 文件链接 ] ,但是当我复制文件链接时,在浏览器中打开,它打开得很好。

我也检查了文件权限,并引用了 Stackoverflow 上的一些答案,但没有任何帮助,请尽快帮助我。

enter image description here

        $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 docs

关于laravel - 无法打开文件进行读取 [ 文件链接 ] laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64521526/

相关文章:

javascript - 使用 Vuejs 的单个数组元素中的多个字段

php - Laravel - foreach 循环返回试图获取非对象的属性

php - 使用 put/post 将数据发送到 Laravel 中的 Web 服务

php - 在 Laravel 5.5 中发送邮件而不创建 Mailable

php - 如何更改从 Controller 发送的电子邮件中的语言环境 - laravel 5.4

php - Laravel 使用 queue() 发送邮件不在服务器上工作

Laravel - 如何在邮件称呼中添加换行符?

laravel - 如何在 Laravel 中转发电子邮件?

php - Laravel Mailable 队列,如何将自定义数据传递给 MessageSent 事件

php - 拉维尔 5.1 : How to limit account access so one account can be accessed at one time