Aid*_*ser 5 php file-storage laravel
I would like to move one of my files from the storage file directory in Laravel to the public file directory in laravel, without changing my file system configuration. Is this possible?
是的,您可以使用Storage::move和public_path()助手来完成。
Storage::move( 'old/file.jpg', public_path('new/file.jpg') );
请注意,old/file.jpg相对于your-project/storage/app,因此您要移动的文件将在your-project/storage/app/old/file.jpg
更新
不过,另一种方法可能是将文件移动/存储在laravel-project/storage/app/public.
然后通过符号链接在公共目录中访问它。
之后,里面的所有文件和目录laravel-project/storage/app/public都将链接到laravel-project/public/storage/目录。然后你可以通过 url 访问该文件。
因此,要以这种方式执行此操作,请将文件移动到 storage/app/public/ 文件夹:
Storage::move( 'old/file.jpg', 'public/movedfiles/file.jpg' );
Run Code Online (Sandbox Code Playgroud)
通过这个 artisan 命令创建符号链接:
php artisan storage:link
Run Code Online (Sandbox Code Playgroud)
然后你可以通过 url 访问文件:
<a href='http://your-domain/storage/movedfiles/file.jpg'>file.jpg</a>
Run Code Online (Sandbox Code Playgroud)
或在刀片
<a href='{{ asset('storage/movedfiles/file.jpg') }}'>file.jpg</a>
Run Code Online (Sandbox Code Playgroud)