Download laravel image

1

I have the following link:

<a href="http://www.codigos-qr.com/barcode/barcode.processor.php?encode=CODE128&bdata={{$row->code}}w&height=40&scale=2&showData=1&Genrate=" title="Generar Codigo" target="_blank">{{ $row->code }}</a>

It generates a barcode in an external url. Is there any way that instead of opening the link with the image, you can download it directly?

    
asked by Erain Moya 16.06.2018 в 23:22
source

1 answer

1

I did the download automatically with curl. Annex code.

$curlCh = curl_init(); 
curl_setopt($curlCh, CURLOPT_URL, $url); 
curl_setopt($curlCh, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($curlCh, CURLOPT_SSLVERSION,3); 
$curlData = curl_exec ($curlCh); 
curl_close ($curlCh); 
$downloadPath = "uploads/codes/$code->code.png"; 
$file = fopen($downloadPath, "w+"); fputs($file, $curlData);       
fclose($file);
    
answered by 18.06.2018 в 23:00