【问题标题】:the images are not displayed correctly online even it works well locally using laravel 6即使使用 laravel 6 在本地运行良好,图像也无法在线正确显示
【发布时间】:2022-01-15 22:36:07
【问题描述】:

我通过laravel 创建了一个网站,该网站在本地运行良好,如果存在则显示图像,如果图像不存在则显示not-found.jpg 图像,并且当我在线托管时 [aswaktinghir.com][1],总是显示not-found.jpg 图像,productImage 函数总是转到第二个图像条件not-found.jpg,即使有图像。

helpers.php

   function productImage($path) 
{
    return $path && file_exists('storage/'.$path) ? asset('storage/'.$path) : asset('img/not-found.jpg');
}

landing-page.blade.php

 @foreach($annonces as $annonce) 
                        <a href="{{ url('annonces/'.$annonce->id) }}"> 
                        <div class="col-md-3 col-xs-12">
                            <div class="blog-item this-animate" data-animate="fadeInUp">
                                <div class="blog-media">
                                    <img src="{{ asset(productImage($annonce->image) )}}" class="img-responsive" style="width: 240px;height: 240px" /> 
                                </div>
                                <div class="blog-data">
                                    <h5>{{ $annonce->details }}</h5>
                                    <span class="blog-date">{{ $annonce->created_at }} / 0 Comments</span>
                                    <p>{{ substr($annonce->description, 0, 31) }}...</p>
                                </div>
                            </div>
                        </div>
                        </a>
                        @endforeach 
                        </div> 

【问题讨论】:

  • 您是否创建了存储符号链接?
  • @TipuSultanEiko 是的,我创建符号链接,我编辑我的函数以`return $path && file_exists('storage/'.$path) ? asset('storage/'.$path) : asset('storage/'.$path);` ,你可以再次看到我的网站link
  • 你检查服务器路径了吗?那些文件存在吗?
  • @TipuSultanEiko 有些图片存在,有些不存在

标签: php laravel helper


【解决方案1】:

如果您使用 Git 将文件传输到生产服务器,请务必查看根目录中的 .gitignore 文件。确保您没有排除 /store 或 /public/store 文件夹。

【讨论】:

  • 不,我使用 filezilla,我创建了符号链接,我将我的函数编辑为 `return $path && file_exists('storage/'.$path) ? asset('storage/'.$path) : asset('storage/'.$path);` ,你可以再次看到我的网站aswak
【解决方案2】:

你试过了吗

chmod -R 755 [path to storage]
chown -R www-data:www-data [path to storage]

【讨论】:

  • 当我运行这个命令它给我错误:The stream or file "/var/www/clients/client1/web1/web/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied请帮助
  • 需要在每条命令前加上“sudo”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-09
  • 2013-02-12
  • 2018-08-04
  • 2018-08-24
  • 2019-04-20
  • 2016-01-30
相关资源
最近更新 更多