$urls = "http://$host:7071/CM/APIUploadUNFileServlet?dse_sessionId=$session_id&serialNo=$serialNo&sha=$sha";//接收文件的地址 $txt_url = storage_path($txt_url);//文件本地存储地址 $new_file = new \CURLFile($txt_url); $dataJson = array( 'file' => $new_file, );
$res = Helper::curlPostStream($urls, $dataJson);//调用封装的方法
//封装的方法 static function curlPostStream($url, $post_data) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); $output = curl_exec($ch); curl_close($ch); return $output; }