Laravel 4从网址获取图片 [英] Laravel 4 get image from url
本文介绍了Laravel 4从网址获取图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,当我想上传图片时。我通常会这样做:
OK so when I want to upload an image. I usually do something like:
$file = Input::file('image');
$destinationPath = 'whereEver';
$filename = $file->getClientOriginalName();
$uploadSuccess = Input::file('image')->move($destinationPath, $filename);
if( $uploadSuccess ) {
// save the url
}
当用户上传图片时,此功能正常。但是如何从URL保存图像???
This works fine when the user uploads the image. But how do I save an image from an 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上传图像?
So, how do I upload an image from a URL with laravel 4??
Amy非常感谢。
推荐答案
我不知道这对你有多大帮助,但你可能想看看干预图书馆。它原本打算用作图像处理库,但它提供了来自网址的保存图像:
I don't know if this will help you a lot but you might want to look at the Intervention Library. It's originally intended to be used as an image manipulation library but it provides saving image from url:
$image = Image::make('http://someurl.com/image.jpg')->save('/path/saveAsImageName.jpg');
这篇关于Laravel 4从网址获取图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文