|
单个文件举个例子,多文件的话可以放在一个文件夹下遍历后提供下载:
- public function aaa(){
- $ddd = "http://47.105.151.181:8012/5fce06e407657/3.jpg";
- $ccc = "http://www.baidu.com/img/baidu_sylogo1.gif";
- $this->httpcopy($ddd);
- }
- public function httpcopy($url, $file="", $timeout=60) {
- $file = empty($file) ? pathinfo($url,PATHINFO_BASENAME) : $file;
- $dir = "Upload/docConversionImage/5fce06e407657/";
- if (!file_exists($dir)){
- mkdir ($dir,0777,true);
- }
- $url = str_replace(" ","%20",$url);
- if(function_exists('curl_init')) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- $temp = curl_exec($ch);
- if(@file_put_contents($dir.$file, $temp) && !curl_error($ch)) {
- return $file;
- }else{
- return false;
- }
-
- }else{
- $opts = array(
- "http"=>array(
- "method"=>"GET",
- "header"=>"",
- "timeout"=>$timeout
- )
- );
- $context = stream_context_create($opts);
- if(@copy($url, $file, $context)) {
- return $file;
- }else{
- return false;
- }
- }
- }
复制代码
|
|