gpt4 book ai didi

image - Laravel 4 从 url 获取图像

转载 作者:行者123 更新时间:2023-12-04 22:13:18 26 4
gpt4 key购买 nike

好的,所以当我想上传图像时。我通常做这样的事情:

$file = Input::file('image');
$destinationPath = 'whereEver';
$filename = $file->getClientOriginalName();
$uploadSuccess = Input::file('image')->move($destinationPath, $filename);

if( $uploadSuccess ) {
// save the url
}

当用户上传图像时,这工作正常。但是如何从 URL 保存图像???

如果我尝试类似的事情:
$url = 'http://www.whereEver.com/some/image';
$file = file_get_contents($url);

然后:
$filename = $file->getClientOriginalName();
$uploadSuccess = Input::file('image')->move($destinationPath, $filename);

我收到以下错误:
Call to a member function move() on a non-object

那么,如何使用 laravel 4 从 URL 上传图像?

非常感谢艾米的帮助。

最佳答案

我不知道这是否会对你有很大帮助,但你可能想看看 Intervention Library 。它最初打算用作图像处理库,但它提供了从 url 保存图像的功能:

$image = Image::make('http://someurl.com/image.jpg')->save('/path/saveAsImageName.jpg');

关于image - Laravel 4 从 url 获取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17776291/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com