PHP图片内容以二进制数据流的形式发送(CurlFile使用)
生活随笔
收集整理的這篇文章主要介紹了
PHP图片内容以二进制数据流的形式发送(CurlFile使用)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//第一個參數:圖片路徑(包括圖片文件)
//第二個參數:圖片格式
//第三個參數:圖片名稱
$obj_cashCard = new CurlFile($param['img_path'], "image/jpg", $param['file_name'] . '.jpg');
實例:?
/*** 日志記錄* @param $data /內容* @param $method /方法名* @param $phone /手機號* @param string $is_big /通道別名* @param string $title /標題*/public function Log($data, $method, $is_big, $title, $phone = ''){$str = is_array($data) ? json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : $data;if (empty($phone)) {$content = '【' . date('Y-m-d H:i:s') . '】' . $title . $str . PHP_EOL;} else {$content = ' phone:' . $phone . '【' . date('Y-m-d H:i:s') . '】' . $title . $str . PHP_EOL;}$path = APPPATH . "../PAYLOG/$is_big/$method/";if (!is_dir($path)) { //判斷目錄是否存在 不存在就創建mkdir($path, 0777, true);}file_put_contents($path . date("Y-m-d") . '.txt', $content, FILE_APPEND);//換行分割file_put_contents($path . date("Y-m-d") . '.txt', '------------------------' . PHP_EOL, FILE_APPEND);}// 上傳圖片postpublic function imgUploadPost($url, $data = array()){$ch = curl_init();curl_setopt($ch, CURLOPT_HEADER, false);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);curl_setopt($ch, CURLOPT_POSTFIELDS, $data);curl_setopt($ch, CURLOPT_URL, $url);//上傳類curl_setopt($ch, CURLOPT_TIMEOUT, 40);$result = curl_exec($ch);if (0 != curl_errno($ch)) {$result['error'] = "Error:\n" . curl_error($ch);}$httpCodes = curl_getinfo($ch);curl_close($ch);return $result;}// 上傳圖片簽名+postpublic function imgsign_post($param, $method, $api_method, $is_big, $phone){$input['reqTime'] = date("YmdHis");//渠道號$input['partnerId'] = $this->partnerId;$this->log($input, $api_method, $is_big, '簽名前數據:', $phone);//簽名$input['signature'] = $this->makeSign($input);$this->log($input['signature'], $api_method, $is_big, '簽名值:');//圖片$obj_cashCard = new CurlFile($param['img_path'], "image/jpg", $param['file_name'] . '.jpg');$input['picture'] = $obj_cashCard;$post_url = $this->zdUrl . $method;ksort($input);$this->log($post_url, $api_method, $is_big, '請求url:');$this->log($input, $api_method, $is_big, '請求報文:');$rs = $this->imgUploadPost($post_url, $input);$this->log($rs, $api_method, $is_big, '響應報文:');return $rs;}?
?
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的PHP图片内容以二进制数据流的形式发送(CurlFile使用)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 0.000000015,等于多少比例尺?
- 下一篇: PHPStrom的快捷键突然失效解决方案