download image file from given google chart api url using php

i want to download image returned by this url using a link like <a href="">Download</a> and on click of this link download box should appear so user can save image to his/her system. here is the url that return image


i don't want to save the image to server is it possible ?


Original Question

You can stream or proxy the file to your users by setting up a simple PHP download script on your server. When user hits the download.php script below it will set the correct headers so that their browsers asks them to save a download. It will then stream the chart image from google to the users browser.

In your HTML:

<a href="download.php">Download</a>

In download.php:

header('Content-Type: image/png'); header('Content-Disposition: attachment; filename="chart.png"'); $image = file_get_contents('http://chart.apis.google.com/chart?chs=300x300&cht=qr&chld=L|0&chl=http%253A%252F%252Fnetcane.com%252Fprojects%252Fyourl%252F3'); header('Content-Length: ' . strlen($image)); echo $image;

Passing in dynamically generated chart API URLs

In your HTML:

<?php $url = 'http://chart.apis.google.com/chart?my-generated-chart-api-url'; <a href="download.php?url=<?php echo urlencode($url); ?>">Download</a>

In download.php:

$url = ''; if(array_key_exists('url', $_GET) and filter_var($_GET['url'], FILTER_VALIDATE_URL)) { $url = $_GET['url']; } header('Content-Type: image/png'); header('Content-Disposition: attachment; filename="chart.png"'); $image = file_get_contents($url); header('Content-Length: ' . strlen($image)); echo $image;


No, not really. Since the image is generated at chart.apis.google.com, and you don't have control over that server, you can't make it send the Content-Disposition header with that image; therefore, browsers will display that image.

What you technically could do (but I'm not sure if Google's ToS allows it, better check), is to link to your server, which will proxy the download and add the Content-Disposition: attachment header.


I believe you will not be able to do that. The closest thing would be to dynamically get the image data using PHP and then serving it with the header <strong>Content-Disposition: attachment; filename=qr.png</strong>

<?php $img_data = file_get_contents("http://chart.apis.google.com/chart?chs=300x300&cht=qr&chld=L|0&chl=http%253A%252F%252Fnetcane.com%252Fprojects%252Fyourl%252F3"); header("Content-Type: image/png"); header("Content-Length: " . strlen($img_data)); header("Content-Disposition: attachment; filename=qr.png"); print $img_data; ?>

Code is untested, but I think you get the gist of it. Hope its what you're looking for.


  • What jQuery map plugin allows specifying the color of the pushpins?
  • How to use a computer's webcam to read a qr code and open a website [Java] [closed]
  • How can I extract the required data from a page with JSON it's source? [closed]
  • Will it ever be possible for $/ to support regexes?
  • Generating QR codes in google-spreadsheet
  • Perl: How to check if any integers in a list of integers are in an array
  • zxing - android - read multiples qr images
  • R: lm and biglm producing different answers
  • How to get QR code from id?
  • LAPACK orthonormalization function
  • Need advice for creating a digitized ticketing admission system
  • How do I get my text centered below the image, not adjacent to it?
  • Replacing multiple occurrences of a char between two string patterns
  • Nested Django tags
  • Passing PHP variables between scripts
  • Creating a for loop to consolidate powershell menu-driven script
  • Xamarin iOS ZXing Barcode read using front camera issue
  • How to call scanned barcode history from zxing
  • Zxing : Unable to Scan Small UPC codes
  • Wordpress Widget Issues
  • Qr-code decoder from image file (react native)
  • Weird Behavior when using Eigen
  • QR decomposition and Choleski decomposition in R
  • Perl regex: how to know number of matches
  • Is there a bug in java.net.SocketPermission when dealing with cname reverse lookup
  • Exponential fitting with R
  • Barcode and QR code Scanner in SAPUI5
  • download image file from given google chart api url using php
  • Is there a way of avoiding so many list(chain(*list_of_list))?
  • how to count all global variables in the cpp file
  • How do I get elements of a hash whose keys match a given regex?
  • Create a table from a list of tuples in Python 3
  • Who propagate bugfixes across branches (corporate development)?
  • xcode don't localize specific strings
  • ilmerge with a PFX file
  • Resize panoramic image to fixed size
  • Volusion's generic SQL folder, functionality
  • How do you join a server to an Active Directory (domain)?
  • coudnt use logback because of log4j
  • Running Map reduces the dimensions of the matrices