如何将laravel 5.3中的存储路径更改为公开? [英] How to change storage path in laravel 5.3 to public?
问题描述
在laravel 5.3
中,如果我从表单上载文件,它将被存储在自己的存储目录中.然后,我应该在公共路径中为该存储路径创建一个symlink
.
In laravel 5.3
, if I upload a file from a form, it will be stored in own storage directory. Then I should create a symlink
to that storage path in public path.
由于限制,我不能在系统上使用创建符号链接.如何将文件直接上传到public/uploads
而不是storage/app/uploads
?
I can't use creating symlinks on my system because of the limitation. How can I upload files directly to public/uploads
instead of storage/app/uploads
?
我试图在AppServiceProvider.php
中设置路径,但是它不起作用.
I tried to set the path in AppServiceProvider.php
but it doesn't work.
public function register()
{
//not working:
$this->app->useStoragePath( $this->app->basePath() . "/upload");
//also not working:
// $this->app->bind('path.storage', function () {
// return $this->app->basePath() . '/upload';
// });
}
不起作用"是指它仍在上载到默认存储目录中.我还清除了缓存.
by "not working" I mean that it is still uploading into the default storage directory. I cleared also the cache.
这是上载部分(在控制器中使用):
Here is the upload part (used in a controller):
$request->image->storeAs("uploads", "uploaded_image.jpg");
感谢您的任何提示. :)
Thanks for any hints. :)
推荐答案
在Laravel 5中,您现在必须在config/filesystems.php
中执行此操作.您可以像这样添加新磁盘:
In Laravel 5 you now have to do this in config/filesystems.php
. You can add a new disk like so:
'disks' => [
'uploads' => [
'driver' => 'local',
'root' => public_path(), // previously storage_path();
],
]
,然后执行以下操作以使用它:
and then do the following to use it:
Storage::disk('uploads')->put('filename', $file_content);
这篇关于如何将laravel 5.3中的存储路径更改为公开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!