![](/img/trans.png)
[英]How do I open a doc or pdf file from php if i have the url using word?
[英]How do I open a file from a URL in Laravel 4
我有一个pdf或图像的URL。 我想获取该文件并将其存储在我的服务器上。
我知道laravel具有File :: get(),但是可以从Web网址打开文件,然后将File :: put()放到服务器上的一个文件夹中吗?
有没有更好的方法来实现这一目标?
谢谢!
这是我所拥有的:
$shared_folder = $destinationPath.'/shared' if(!File::isDirectory($shared_folder)){ File::makeDirectory($shared_folder,0777,true,true); File::get($attachment->link); $file_name =$file->getClientOriginalName(); File::put($shared_folder,$file); $new_location = $shared_folder = $destinationPath.'/shared/.'.$file_name; }
我知道laravel具有File :: get(),但是可以从Web网址打开文件,然后将File :: put()放到服务器上的一个文件夹中吗?
否-这只会访问本地资源。
您需要使用cURL并访问资源。 我建议使用Guzzle软件包 ,该软件包允许使用cURL的简便方法。
那你可以做这样的事情
function getFile($fromUrl, $toFile) {
$client = new Guzzle\Http\Client();
$response = $client->get($fromUrl);
->setResponseBody($toFile)
->send();
return true;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.