如何访问存储文件

How to Access the Storage File

如何访问存储中的文件。

文件位置

storage/uploads/documentUpload/3_1620028799.PNG

记住php artisan storage link 将不起作用,因为文件不在 app/public 文件夹中。

文件 URL http://example.com/storage/uploads/logo/logo.png 404 错误。 有什么方法可以在 htaccess 中覆盖吗?

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

您可以在 config/filesystems.php 中创建一个新磁盘,例如上传

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

并在 config/filesystems.php 文件的末尾,为上传文件夹添加一个新的符号链接

'links' => [
    public_path('storage') => storage_path('app/public'),
    public_path('storage/uploads')  => storage_path('app/uploads'), // Add this
],

然后运行php artisan storage:link

每当你想获取文件的url时,只需运行

\Storage::disk('uploads')->url('documentUpload/3_1620028799.PNG');