-2
Dear friends, I have the code below that works as follows, it makes a request via Curl, brings me a file, but this being necessary to click save in the browser, I would like to simply open the command and the file was sent to a local folder "/images on localhost, could help?
*** the file is private only I will use on the server, download at scheduled times with a cron and make a future comparison with array_diff, it is not a public file.
<?php
header("Content-Type: application/zip");
header("Content-Disposition: inline; filename=test.zip");
$token = file_get_contents("http://localhost/novoprojeto/token.php");
$curl = curl_init();
$imagem = "084301";
curl_setopt_array($curl, array(
CURLOPT_URL => "http://api/api/imagem/download-zip/$imagem",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array( "Authorization: Bearer $token"
),
));
$response = curl_exec($curl);
curl_close($curl);
Is there a specific reason you use Curl instead of
file_get_contents()
to get the file? I don’t see a reason to use Curl.– Vinicius Gabriel