laravel - 将 putFileAs 与外部文件 Laravel 一起使用
问题描述
我正在寻找使用存储外部文件的方法,putFileAs
但是遇到了一些麻烦。
甚至可能吗?
注意:我不想put
作为替代方案。因为我想指定文件夹路径。
$image = Storage::putFileAs(
'images',
'http://path.to/some/external/image.jpg',
str_random() . '.jpg'
);
我收到错误
调用字符串上的成员函数 getRealPath()
编辑:我将我的代码编辑为
$image = Storage::putFileAs(
'images',
file_get_contents('http://path.to/some/external/image.jpg'),
str_random() . '.jpg'
);
但我又得到一个错误:
Symfony\Component\Debug\Exception\FatalThrowableError : Call to a member function getRealPath() on string
at /home/vagrant/code/laravelapp/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php:222
218| * @return string|false
219| */
220| public function putFileAs($path, $file, $name, $options = [])
221| { >
222| $stream = fopen($file->getRealPath(), 'r');
223|
224| // Next, we will format the path of the file and store the file using a stream since
225| // they provide better performance than alternatives. Once we write the file this
226| // stream will get closed automatically by us so the developer doesn't have to.
解决方案
laravel 5.5上的错误。
使用Storage::put作为文件内容。
$image = Storage::put(
'images/'.str_random(). '.jpg',
file_get_contents('http://path.to/some/external/image.jpg')
);
推荐阅读
- javascript - 如何从通过 WebRequest 对象加载的页面调用 javascript 函数
- laravel-envoy - 我在特使脚本中提供了密码,但它提示手动输入密码
- android - Pjsip Android 视频通话:倒转视频预览
- javascript - javascript如何解析参数?
- angular - 为什么在使用 [ngModel]="true" 时每个生命周期挂钩上的 this.value 未定义/为空
- javascript - Angular UI 路由器刷新正在处理父状态问题
- tensorflow - Keras:KMP_AFFINITY 是关键输出吗?
- delphi - Delphi 6中如何将TVirtualStringTree的所有节点保存到BMP?
- r - 与excel表相关的R官员图
- javascript - 如何使 jquery gridnav 库兼容并使用 jquery 3.3.1