Laravel 5.3 存储找不到上传的文件

Laravel 5.3 storage cant find uploaded file

我正在使用laravel Filesystem 来存储图片,图片将在默认存储中上传,示例:

/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
}

这会像这样打印图像 url,

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

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

您只需更改 config\filesystems。php 形式

'default' => local,

'default' => public,

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

然后试试上面的代码就可以了

对我来说,当我将 "../" 添加到文件的 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);