Created
May 3, 2023 13:50
-
-
Save magemore/61ebf4c31f5b246eb23215c9cc0f1168 to your computer and use it in GitHub Desktop.
curl fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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