【发布时间】:2021-08-10 09:09:43
【问题描述】:
我在公共目录为 public_html 的共享服务器上托管了我的 laravel 应用程序。订单发票路径应为/var/www/html/public_html/user_invoices/invoice_order_447B11621531373227.pdf
- Laravel 版本:5.7
- Dompdf:“barryvdh/laravel-dompdf”:“^0.9.0”
我收到此错误:
错误异常: file_put_contents(/var/www/html/myproject/public_html/user_invoices/invoice_order_447B11621531373227.pdf): 无法打开流:中没有这样的文件或目录 /var/www/html/crm/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:122
这是我的可邮寄课程:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use PDF;
class UserNotificationsOrderPlaced extends Mailable
{
public $data;
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$path = public_path('user_invoices/invoice_order_'.$this->data[0]->order_id.'.pdf');
$pdf = PDF::loadView('pdf.invoice', ['order'=>$this->data[0]])->save($path);
return $this->view('emails.orders')->with(['orders'=>$this->data])->attach($path);
}
}
AppServiceProvider:
我已经尝试了 realpath 和 base_path 这两种解决方案,但仍然遇到同样的错误:
return realpath(base_path().'/../public_html');
return base_path().'/../public_html';return realpath(base_path().'/public_html');
return base_path().'/public_html';
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//Schema::defaultStringLength(191);
if (class_exists('Swift_Preferences')) {
\Swift_Preferences::getInstance()->setTempDir(storage_path().'/tmp');
} else {
\Log::warning('Class Swift_Preferences does not exists');
}
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind('path.public', function() {
return realpath(base_path().'/../public_html');
//return base_path().'/../public_html';
});
}
}
【问题讨论】:
-
你试过了吗? $this->app->bind('path.public', function() { return base_path('public_html'); });
-
由于服务器的文件夹结构,您不应该更改公共路径。进入public_html/index.php,根据应用路径更新所需文件的路径。其他一切都会正常工作。
-
将您的应用程序文件从
/var/www/html/myproject移动到/var/www/html,然后检查以确保config/filesystems.php引用了正确的公共路径 -
更改
config('filesystems.disks.public.root');怎么样?