The problem you're having is with the basename
of the URL, you're trying to set as file name, which results in something like C:\TEMP\chart?chs=150x150&cht=qr&chl=toto
, which isn't a valid file name.
Also you can't "download" the image using file_get_contents
. You'll need to use cURL
. Something like this should do the job:
$imageUrl = 'https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=toto';
$imgPath = sys_get_temp_dir() . '/' . 'qr.png';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $imageUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$raw = curl_exec($ch);
if (is_file($imgPath)) {
unlink($imgPath);
}
$fp = fopen($imgPath, 'x');
fwrite($fp, $raw);
fclose($fp);
And then you can use $imgPath
to create the PDF image.