標籤:資訊 head pos char ini ica code 請求 header
1 /** 2 * 發送POST請求 3 */ 4 function doPost2($url, $postdata) { 5 //初始化 6 $curl = curl_init(); 7 // 設定post方式提交 8 curl_setopt($curl, CURLOPT_POST, 1); 9 // 設定抓取的url10 curl_setopt($curl, CURLOPT_URL, $url);11 // 設定提交的資料12 curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);13 // 設定擷取的資訊以檔案流的形式返回,而不是直接輸出。14 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);15 //設定標頭檔的資訊作為資料流輸出16 curl_setopt($curl, CURLOPT_HTTPHEADER, array(‘application/x-www-form-urlencoded;charset=utf-8‘));17 18 $res = curl_exec($curl);19 //關閉URL請求20 curl_close($curl);21 22 return $res;23 }
1 /** 2 * 上傳圖片到cdn伺服器上 3 * @param string file_path 圖片的絕對位址 4 * @return string 返回圖片地址 5 */ 6 function upload_cdn($file_path) { 7 if (class_exists(‘\CURLFile‘)) {// 這裡用特性檢測判斷php版本 8 $file_path = new \CURLFile(realpath($file_path));//>=5.5 9 } else {10 $file_path = ‘@‘.$file_path;//<=5.511 }12 13 $url = "伺服器位址";14 15 $data = array(16 ‘imgfile1‘=>$file_path,17 ‘PHPSESSID‘=>‘ba4d1587aab023fd8cfa28fbe36c8235‘,18 ‘totalform‘=>‘1‘19 );20 21 $result = doPost2($url,$data);22 23 return $result;24 25 }
上傳圖片到cdn伺服器