0

i would like to extract the gz file downloaded with api with my script curl.

here is my script :

    <?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://x/x/x.sql.gz',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => 'accept-encoding : gzip, deflate, br',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Authorization: Basic x'
  ),
));
$response = curl_exec($curl);
$destination = "dump.sql";
$file = fopen($destination, "w+");
fputs($file, $response);
fclose($file);
curl_close($curl);

at the moment all that i get is the gz file, i tried manythings, and now i am stacked.

Thank you for your help

Christian Baumann
  • 3,188
  • 3
  • 20
  • 37
Ôokami
  • 21
  • 6
  • Did you mean "stuck" rather than "stacked"? How are you stuck exactly? What did you try? What went wrong? I'm pretty sure there will be examples online of how to extract a gz file from PHP already. We need a specific problem in an attempt to implement this, and a [mre] of the issue shown in your question, rather than what appears to be just another request for a tutorial which would probably just show the things you claim to have already tried. See also [ask]. Thanks. – ADyson May 10 '22 at 15:55
  • 1
    Does this answer your question? [How can I extract or uncompress gzip file using php?](https://stackoverflow.com/questions/11265914/how-can-i-extract-or-uncompress-gzip-file-using-php) – Chris Haas May 10 '22 at 17:20
  • 1
    If you are after uncompressing on the fly, you could try with `stream_filter_append` with `zlib.inflate`. If I understand correctly, it provides for a stream that decompresses and writes to the file. – Seva Alekseyev May 10 '22 at 17:44

0 Answers0