简体   繁体   中英

How to download file to my server (Yii framework) from another server?

I need my webapp to create a file on the server from another server. Input parameter is URL of a remote file. I stumbled upon cURL wrapper for Yii. Is it right tool for my task?

I found a solution. No need of third-party modules. Here is a draft version:

<?php
$f1 = fopen($_REQUEST['pic_url'],'r');
$fcontent = $contents = stream_get_contents($f1);
fclose($f1);

$fileName = microtime().'.'.CFileHelper::getExtension($_REQUEST['pic_url']);

$f2 = fopen(Yii::app()->basePath.'/../images/'.$fileName,'c+');
fwrite($f2,$fcontent,strlen($fcontent));
fclose($f2);
?>

Basically this code reads an image on remote server and saves it on home server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM