在Storage::put($filename, $content)
的第二个参数是指原始信息,构成了该文件。对于文本文件,$content
将是文本,而对于图像来说,它将是组成图像的原始信息。
由于您使用的是干预图像,因此您可以使用encode()
方法来获取存储所需的数据。
// Assuming that $file is your Intervention Image instance
// Example 1: Save as the default type (JPEG)
Storage::put('public/images/my_profile.jpeg', $file->encode());
// Example 2: Save as a PNG
Storage::put('public/images/my_profile.png', $file->encode('png'));
在问候你如何来指代路径作为URL的问题,一定要遵循从文档下面的代码片段:
注:当使用本地驱动程序,确保在public/storage中创建一个指向storage/app/public目录的符号链接。
之后,你就可以从storage/app/public
从浏览器访问一切都像这样:
echo config('app.url') . str_replace('/public/', '/', Storage::url('public/images/my_profile.png'));
// Echoes "http://localhost/storage/images/my_profile.png"
https://laravel.com/docs/5.2/filesystem'放(文件名,目录)' –
在文档Mike B链接(搜索头像)中有一个保存二进制文件的例子。 – herrjeh42
我已经做过,但仍然困惑的是什么$内容是在Storage :: put('file.jpg',$ content); :( – Rahul