尝试从我的视图访问“ storage / app / folder1 / a.png”
public function viewStorageFiles()
{
$fileFullPath = Storage::disk('local')->path('folder1/a.png');
$fileUrl = Storage::disk('local')->url('app/folder1/a.png');
$storage_path = storage_path('app/folder1/a.png');
return view('email.fileDownload')->with([
'fileFullPath' => $fileFullPath,
'fileUrl' => $fileUrl,
'storage_path' => $storage_path,
]);
}
查看中:email.fileDownload
<div>
<p> asset($fileUrl) ==> {{asset($fileUrl)}}</p>
<img src="{{asset($fileUrl)}}"/>
</div>
<div>
<p> url($fileUrl) ==> {{url($fileUrl)}}</p>
<img src="{{url($fileUrl)}}"/>
</div>
<div>
<p> storage_path($fileUrl) ==> {{storage_path($fileUrl)}}</p>
<img src="{{storage_path($fileUrl)}}"/>
</div>
对此可能会有很多答案!
您可以create a symbolic link from "public/storage" to "storage/app/public"
使用以下命令:
php artisan storage:link
上面的命令会将您的storage/app/public
目录映射到public
目录。
现在,让我们考虑一下目录中是否有user1.jpg
和user2.jpg
文件storage/app/public
,您可以通过以下方式访问它们:
http://your-domain.com/storage/user1.jpg
http://your-domain.com/storage/user2.jpg
*根据您的评论更新了我的答案:*
您可以从受某些中间件保护的路由返回文件响应!
例如,以下路由从storage/app/uploads
无法公开访问的目录返回文件响应:
Route::get('storage/{file}', function ($file) {
$path = storage_path('app' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . $file);
return response()->file($path);
});
无论如何,您都可以固定在上述路线上,并在您的视图中使用它。
希望对您有所帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句