php 通过本地路径获取文件上传

        $absolutepath=dirname(__FILE__)."/"."upload/aa.jpg" 
        $data = [
            'binFile'=>new \CURLFile($absolutepath),
            'filename'  =>  "文件名字"
        ];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->url);
        curl_setopt($ch, CURLOPT_POST, true );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,60);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'token:'sd4a7sd45a4dqwe'
          ));
        $result = curl_exec($ch);
        $info = curl_getinfo($ch);
        curl_close($ch);
        print_r($result);

猜你喜欢

转载自blog.csdn.net/zhang804633234/article/details/121264144
今日推荐