如何为QR码创建下载链接?

I'm using the QR google api to create QR codes but would like the ability to download the image in PHP. I've looked online but can't seem to find anything helpful. Any suggestions?

I'm creating the QR code like so:

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')); 

You can use a any binary safe function to retrieve and output the image with the right headers.

Remeber that allow_fopen_url must be On in PHP configuration.

Something like:

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');

if you want to download the file onto your webserver(and save it), just use copy()

copy($url, 'myfile.png');

This will not prompt a visitors web browser to save the file.