• tp5 上传文件从一个服务器到另一个服务器


    /**
    * 上传文件的主处理方法
    * @return mixed
    */

    public function upFile()
    {
    //先把上传文件放到本地服务器,然后移动到远端服务器
    $file=request()->file('file');
    if(empty($file)){
    return $this->_returnData('201','数据为空');
    }
    $filepath=ROOT_PATH.'public'.DS.'uploads'.DS.'video';
    $info = $file->move($filepath);
    $filename = $info->getSaveName();
    //得到本地视频路径
    $path=$filepath.DS.$filename;
    //要上传的远端服务器的地址
    $url = "http://192.168.30.189/test.php";
    //通过curl上传到远端服务器
    $ch = curl_init();
    if (class_exists('CURLFile')) {
    $file = new CURLFile($path);
    // 禁用"@"上传方法,这样就可以安全的传输"@"开头的参数值
    curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
    } else {
    $file = '@'.$path;
    }
    curl_setopt($ch , CURLOPT_URL , $url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_POST,true);
    curl_setopt($ch,CURLOPT_POSTFIELDS,array('file_via_curl' => $file));
    //远端的视频路径
    $result = curl_exec($ch);
    curl_close($ch);
    //把视频路径返回给前端
    if(!empty($result)){
    return $this->_returnData('200','视频地址',$result);
    }else{
    return $this->_returnData('200','数据为空');
    }
    }
  • 相关阅读:
    深度学习练习(三)
    深度学习核心技术笔记(一)
    tensorflow的函数
    举例
    Tensorflow 笔记
    tensorflow框架
    基于python的感知机
    深度学习练习(一)
    深度学习练习(二)
    [javascript 实践篇]——那些你不知道的“奇淫巧技”
  • 原文地址:https://www.cnblogs.com/ymdphp/p/11463133.html
Copyright © 2020-2023  润新知