日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

PHP图片内容以二进制数据流的形式发送(CurlFile使用)

發布時間:2024/9/19 php 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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使用)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。