上傳圖片到cdn伺服器

來源:互聯網
上載者:User

標籤:資訊   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伺服器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.