![](/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.