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

//第一个参数:图片路径(包括图片文件)

//第二个参数:图片格式

//第三个参数:图片名称

$obj_cashCard = new CurlFile($param['img_path'], "image/jpg", $param['file_name'] . '.jpg');

实例:

060b0032dffb4b6f5afc4a3a9b96374f.png

/**

* 日志记录

* @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);

}

// 上传图片post

public 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;

}

// 上传图片签名+post

public 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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值