【问题标题】:Laravel 5.3 storage cant find uploaded fileLaravel 5.3 存储找不到上传的文件
【发布时间】:2017-04-13 16:26:26
【问题描述】:

我使用laravelFilesystem存储图片,图片会上传到默认存储里面,例如:

/home/user/Projects/mywebapp/storage/app/images/posts/1/e392e17926559e7cc4e7934f.png

我没有更改config/filesystem.php,这是我上传图片的控制器方法,

public function storeImage( Request $request ) {
  $image = $request->file( 'image' )->store( 'images/posts/'.Auth::user()->id );
  echo Storage::url( $image ); // <- print the url of the uploaded image
}

这将像这样打印图像网址,

http://localhost:8000/storage/images/posts/1/e392e17c6a8d7926559e8e7cc4e7934f.png

但是无法从浏览器访问图像文件! 我不想使用 php 来动态获取图像,我只是想让它们通过 http 公开访问。如何显示图片?

【问题讨论】:

    标签: php laravel laravel-5.3 php-7


    【解决方案1】:

    你只需要更改 config\filesystems.php 表单

    'default' => local,
    

    'default' =&gt; public,

    然后在控制台运行php artisan storage:link

    然后试试上面的代码,它会工作的

    【讨论】:

      【解决方案2】:

      对我来说,当我将 "../" 添加到文件的 url 时它起作用了:

      @foreach($arquivos as $i)
      
       <li class="list-group-item"> <img src="{{ asset('img/pdf.png') }}" /> <a href=" {{ asset('../storage/app/public/'.$i->arquivo) }}" target="blank"> {{ $i -> nome }} </a> </li>
      
      @endforeach
      

      我正在像这样保存文件:

      $ext = $request->arquivo->extension();
      $path = $request->arquivo->storeAs('/relatorios', $nameoffile. "." . $ext);
      

      【讨论】:

        猜你喜欢
        • 2017-02-23
        • 2017-02-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多