更改 Laravel 5.4(存储文件夹)中的默认“符号链接”文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44956131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:16:14  来源:igfitidea点击:

Change default "symbolic link" folder in laravel 5.4 (storage folder)

phplaravelhyperlinkstoragedirectory

提问by twis

I'm making a new version of my site with laravel 5.4 and want to keep the same links than my old site has.

我正在使用 laravel 5.4 制作我的网站的新版本,并希望保持与旧网站相同的链接。

My old site has links images like this: domain.com/uploaded/cat.jpg

我的旧网站有这样的链接图片: domain.com/uploaded/cat.jpg

In laravel, its necesary to create a symbolic linkto show the stored images but it saved them with a default folder named storage", like this: domain.com/storage/cat.jpg

在 Laravel 中,需要创建一个符号链接来显示存储的图像,但它使用名为storage"的默认文件夹保存它们,如下所示: domain.com/storage/cat.jpg

How can i change the default name to "uploaded" or whatever?

如何将默认名称更改为“已上传”或其他名称?

I tried to change urlinside the file \config\filesystems.phpwith this:

我尝试使用以下命令更改文件\config\filesystems.php 中的url

Before

'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],

After

'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/uploaded',
        'visibility' => 'public',
    ],

and my controller

和我的控制器

$request->file('image')->storeAs('public', 'example.jpg');

采纳答案by OuailB

Make sure you've created a symlink.

确保您已创建符号链接。

According to your configuration, you can run this command :

根据您的配置,您可以运行以下命令:

ln -s storage/app/public public/uploaded

Then, you can access your files :

然后,您可以访问您的文件:

Storage::disk('public')->url('example.jpg')

Or simply using asset()helper :

或者简单地使用asset()helper :

asset('uploaded/example.jpg');

回答by Lalit Sharma

Execute this code in your server using any php file to create the symbolic link. Once the link has been created, the files will become publicly accessible.

使用任何 php 文件在您的服务器中执行此代码以创建符号链接。创建链接后,文件将变为可公开访问的。

target = '/home/cfrcoclm/public_html/agencies/storage/app/public'
shortcut = '/home/cfrcoclm/public_html/agencies/uploaded' symlink(target, shortcut) ec ho("Link Created!") `

目标 = '/home/cfrcoclm/public_html/agencies/storage/app/public'
快捷方式 = '/home/cfrcoclm/public_html/agencies/uploaded' 符号链接(目标,快捷方式)回声(“链接创建!”)`

回答by Dunsin Olubobokun

In case you do not have SSH access, you can as well write this one-line script below and run it on your server - taking into consideration the right directory path

如果您没有 SSH 访问权限,您也可以在下面编写此单行脚本并在您的服务器上运行它 - 考虑正确的目录路径

symlink('/home/domainname/laravelprojectname/storage/app/public','/home/domainname/public_html/storage');

符号链接('/home/domainname/laravelprojectname/storage/app/public','/home/domainname/public_html/storage');