php中图片以字节流的形式直接发送七牛

2023-06-25,,

PHP 是弱类型语言,没有bytes[]类型, 而 file_get_contents 获取到的是 string,不是byte[],file_get_contents()函数得到的不是流数据,而是string类型,转换成 base64使用二进制输出即可

$content = file_get_contents("file:///Users//s.jpg");
$content = base64_encode($content);然后进行网络传输,对方就能处理数据。

七牛中的直接调用api即可实现:

$key = $invite.'.png';
header('Content-Type: '.$qrCode->getContentType()); //资源类型
$content = $qrCode->writeString(); //数据流形式传递
Yii::$app->Qiniu->manageQiniu($key,$content,'','uploadbinary');