2012-02-17 1 views
1

QR 코드를 생성하기 위해 QR google api를 사용하고 있지만 PHP에서 이미지를 다운로드하고 싶습니다. 온라인에서 보았지만 도움이 될만한 것을 찾지 못했습니다. 어떤 제안?QR 코드 다운로드 링크를 어떻게 만듭니 까?

나는과 같이 QR 코드를 만드는거야 :

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

file_get_contents oO – dynamic

+0

아마도 관련 : http://stackoverflow.com/questions/900207/return-a-php-page-as-an-image – cspray

+0

"PHP에서 이미지 다운로드"란 무엇을 의미하는지 확실하지 않습니다. 물론 urlencode로 URL을 인코딩해야합니다. – satoshi

답변

3

는 당신이 바로 그 헤더 이미지를 검색하고 출력하기 위해 바이너리 안전 기능을 사용할 수 있습니다.

PHP 구성에서 allow_fopen_url이 On이어야합니다.

뭔가 같은 :

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

물론 이것은 다른 출력보다 먼저 보내야하거나 출력 버퍼링이 php.ini의 allow_url_fopen = 1 인 경우 –

1

방금 ​​저장하기 위해 방문자의 웹 브라우저 메시지를 표시하지 않습니다 copy()

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

이를 사용 (및 저장) 웹 서버에 파일을 다운로드하려면 파일.

+0

에 있어야합니다 –