【发布时间】:2011-12-13 22:57:21
【问题描述】:
我基本上是在尝试使用 Google 的 QR Code API 从字节数组中创建 QR 码。我已经尝试通过谷歌的网络后端为“chl”变量(二维码的数据)传递一个字节数组,但它似乎从来不喜欢它。我使用 Google 的 PHP 示例作为我的代码的基础,但如果有人知道使用 Google 的 API 将字节数组简单地转换为 QR 码的另一种方法,那就是唯一的目标。
<?php
// Create some random text-encoded data for a QR code.
//header('content-type: image/png');
$url = 'https://chart.googleapis.com/chart?chid=' . md5(uniqid(rand(), true));
$chd = file($_FILES["file"]["tmp_name"]);
// Add image type, image size, and data to params.
$qrcode = array(
'cht' => 'qr',
'chs' => '300x300',
'choe' => 'ISO-8859-1',
'chl' => $chd);
// Send the request, and print out the returned bytes.
$context = stream_context_create(
array('http' => array(
'method' => 'POST',
'content' => http_build_query($qrcode))));
fpassthru(fopen($url, 'r', false, $context));
?>
有 PHP,处理上传的文件并通过字节数组发送到 Google 的 API。
【问题讨论】:
-
请向我们展示您尝试过的代码。
-
您可以尝试将数据转换为十六进制。
-
添加了一些 PHP 尝试从上传的文件发送字节数组。
标签: php google-api qr-code