Laravel 4从网址获取图片

use*_*871 4 upload image laravel laravel-4

好的,所以当我想上传图片时.我经常这样做:

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

if( $uploadSuccess ) {
    // save the url
}
Run Code Online (Sandbox Code Playgroud)

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

如果我尝试类似的东西:

$url = 'http://www.whereEver.com/some/image';
$file = file_get_contents($url);
Run Code Online (Sandbox Code Playgroud)

然后:

$filename = $file->getClientOriginalName();
$uploadSuccess = Input::file('image')->move($destinationPath, $filename);
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Call to a member function move() on a non-object
Run Code Online (Sandbox Code Playgroud)

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

艾米非常感谢.

小智 10

我不知道这对你有多大帮助,但你可能想看看干预库.它最初打算用作图像处理库,但它提供了来自url的保存图像:

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