2017-10-19 52 views
1

我对与laravel合作非常新,而我真的不明白它如何处理文件。我遵循文档中的说明,按照指示使用php artisan storage:link,但不行。我甚至无法通过访问他们在我的网址中的位置来查看图片。Laravel - 图像没有加载到生产服务器,在当地工作正常

这是我的config/filesystems文件:

<?php 

return [ 

/* 
|-------------------------------------------------------------------------- 
| Default Filesystem Disk 
|-------------------------------------------------------------------------- 
| 
| Here you may specify the default filesystem disk that should be used 
| by the framework. The "local" disk, as well as a variety of cloud 
| based disks are available to your application. Just store away! 
| 
*/ 

'default' => env('FILESYSTEM_DRIVER', 'local'), 

/* 
|-------------------------------------------------------------------------- 
| Default Cloud Filesystem Disk 
|-------------------------------------------------------------------------- 
| 
| Many applications store files both locally and in the cloud. For this 
| reason, you may specify a default "cloud" driver here. This driver 
| will be bound as the Cloud disk implementation in the container. 
| 
*/ 

'cloud' => env('FILESYSTEM_CLOUD', 's3'), 

/* 
|-------------------------------------------------------------------------- 
| Filesystem Disks 
|-------------------------------------------------------------------------- 
| 
| Here you may configure as many filesystem "disks" as you wish, and you 
| may even configure multiple disks of the same driver. Defaults have 
| been setup for each driver as an example of the required options. 
| 
| Supported Drivers: "local", "ftp", "s3", "rackspace" 
| 
*/ 

'disks' => [ 

    'local' => [ 
     'driver' => 'local', 
     'root' => storage_path('app'), 
    ], 

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

    'img' => [ 
     'driver' => 'local', 
     'root' => storage_path('images') 
    ], 

    's3' => [ 
     'driver' => 's3', 
     'key' => env('AWS_KEY'), 
     'secret' => env('AWS_SECRET'), 
     'region' => env('AWS_REGION'), 
     'bucket' => env('AWS_BUCKET'), 
    ], 

], 

]; 

,这是我如何我打电话图像模板:

<img src="{{asset('storage/images/icons/icon.png')}}"> 

我检查,并将图像实际上位于ROOT/storage/app/public/images

我在这里做错了什么?最重要的是,为什么在我的本地环境中,而不是在我的生产服务器中,这一切都可以正常工作?

有关其他信息:生产服务器由Hostgator托管在我公司主站点的子域中。我不知道这是否是一个问题,因为我说我对这件事情是新的。

+0

你能列出公用文件夹中的图像吗? (ls public/storage/images /图标)。如果图像在那里,我认为它可能是主机中的重定向模块的问题 –

+0

如果这些是静态资产(未上传),您可以将它们保存在'ROOT/public/images'中,并用' ' – ljubadr

+0

也从项目根目录'ls -l public/|中检查生产服务器。 grep storage'来查看符号链接是否存在 – ljubadr

回答

1

您在刀片模板中使用的asset助手为您提供了public资产的路径,即位于Laravel应用程序的public文件夹中的资产。您的静态资产(例如徽标,背景图片等)应该保存在您的应用服务所在的目录public内。

storage目录通常用于资产上传由用户在您的应用程序中,例如用户上传新的个人资料图片。要获取存储路径,您可以使用storage_path帮助函数来检索路径。或者,您可以使用Storage::url()方法来检索存储路径的完整URL。

相关问题