laravel - php artisan storage:共享主机上的链接未显示图像
问题描述
我一直在开发一个 laravel 应用程序,因此出于安全原因,我将所有公共文件放在位于 public_html 的基本文件夹中,而其他文件已放在 public_html/secondBase 中。
现在,当我执行命令时:php artisan storage:link出现以下错误。
ErrorException
symlink(): No such file or directory
at vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:265
261| */
262| public function link($target, $link)
263| {
264| if (! windows_os()) {
> 265| return symlink($target, $link);
266| }
267|
268| $mode = $this->isDirectory($target) ? 'J' : 'H';
269|
我厌倦了下面的解决方案
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
public function register()
{
$this->app->bind('path.public', function() {
return base_path() . '/public_html/base';
});
}
我尝试过的第二种方法是制作文件symlink.php,但图像仍然损坏。
符号链接.php
<?php
symlink('/home/hmm/public_html/secondBase/storage/app/public','/home/hmm/public_html/base/storage');
最后我在出现第一个错误的地方做了这条路线。
Route::get('/clear', function () {
Artisan::call('route:clear');
Artisan::call('storage:link', [] );
});
谢谢你的帮助。
解决方案
Go to /public directory and run:
rm storage
Go to Laravel root directory and run:
php artisan storage:link
当 laravel 项目被移动/复制到其他文件夹时,就会出现这个问题。
存储链接仍然存在,因此导致异常错误。public/storage 文件夹存在并指向错误的位置,需要使用 rm storage 命令将其删除。
之后在终端中运行 php artisan storage:link ,它将创建存储链接。
每次移动/复制/部署 laravel 时都需要这样做!
推荐阅读
- java - Java 11 Lambda - 检查每个对象,满足第一个条件时返回 true,否则返回 false
- c++ - C++:错误:获取临时地址 [-fpermissive]
- java - 实现 OpenBeans openbeans-1.0.jar 时出错
- flutter - 您如何确保列内容在一行列中保持在顶部?
- c++ - 尝试根据模板类型在模板类中重载虚函数
- html - (角度)单击一个按钮会突出显示另一个按钮,因为我正在更改数组中的值。为什么?
- python - 比较 CSV 中的行数与 Pandas 成功处理成数据帧的行数?
- laravel - laravel 和 phpunit: 找不到驱动程序 (SQL: PRAGMA foreign_keys = ON;)
- macos - 如何在 macOS 10.14 上配置 MySQL 8.0.21 以使用来自 8.0.18 的数据库
- c# - C# AVL 树查找和插入