Skip to content

Instantly share code, notes, and snippets.

@magemore
Created May 3, 2023 13:50
Show Gist options
  • Save magemore/61ebf4c31f5b246eb23215c9cc0f1168 to your computer and use it in GitHub Desktop.
Save magemore/61ebf4c31f5b246eb23215c9cc0f1168 to your computer and use it in GitHub Desktop.
curl fix
$chD = curl_init();
curl_setopt_array($chD, array(
CURLOPT_URL => $ReportDocArray['url'],
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_BINARYTRANSFER => true, // Set to true for binary files
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($chD);
// Get the size of the headers
$header_size = curl_getinfo($chD, CURLINFO_HEADER_SIZE);
// Separate the headers from the body content
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
// Close curl resource
curl_close($chD);
// Decompress the body content
$decompressed = gzdecode($body);
header('Content-Disposition: attachment; filename="report.txt"');
// Echo the decompressed body content (not the headers)
echo $decompressed;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment