public function curl_post($path,$id){ $curl = curl_init(); if (class_exists('\CURLFile')) { curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true); $data = array( 'file' => new \CURLFile(realpath($path)), 'id'=>$id, );//>=5.5 } else { if (defined('CURLOPT_SAFE_UPLOAD')) { curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false); } $data = array( 'file' => '@' . realpath($path), 'id'=>$id, );//<=5.5 } $url = "http://first123.com/NewSong/Index/uplod"; curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, 1 ); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_USERAGENT,"TEST"); $result = curl_exec($curl); $error = curl_error($curl); echo $error; }
php curl上传文件
最新推荐文章于 2023-12-20 17:25:19 发布