我正在使用二维码谷歌api创建二维码,但希望能够下载的PHP图像。我在网上找过了,但似乎找不到任何有用的东西。有什么建议吗?
我创建的二维码如下:
function generateQR($url, $width = 150, $height = 150) {
$url = urlencode($url);
$image = '<img src="http://chart.apis.google.com/chart?chs='.$width.'x'.$height.'&cht=qr&chl='.$url.'" alt="QR code" width="'.$width.'" height="'.$height.'"/>';
return $image;
}
echo(generateQR('http://google.com')); 发布于 2012-02-18 04:03:00
您可以使用任意二进制安全函数来检索和输出具有正确标题的图像。
请记住,allow_fopen_url必须在PHP配置中处于打开状态。
类似于:
function forceDownloadQR($url, $width = 150, $height = 150) {
$url = urlencode($url);
$image = 'http://chart.apis.google.com/chart?chs='.$width.'x'.$height.'&cht=qr&chl='.$url;
$file = file_get_contents($image);
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=qrcode.png");
header("Cache-Control: public");
header("Content-length: " . strlen($file)); // tells file size
header("Pragma: no-cache");
echo $file;
die;
}
forceDownloadQR('http://google.com');发布于 2012-02-18 04:13:03
如果您想要将文件下载到您的want服务器(并保存),只需使用copy()
copy($url, 'myfile.png');这不会提示访问者web浏览器保存该文件。
https://stackoverflow.com/questions/9334485
复制相似问题