Question

I am working with a client on getting a gzip from their webservice. I am able to get a response with my following call:

$response = $client->call('branchzipdata', $param);
$filename = "test.gzip";
if (!$handle = fopen($filename, 'a')) {
     echo "Cannot open file ($filename)";
     exit;
}

if (fwrite($handle, $response) === FALSE) {
    echo "Cannot write to file ($filename)";
    exit;
}

Now when I attempt to write that a file, such as 'test.gzip', I am unable to open it afterwards... most likely because I am doing something horrible wrong. Any insight would be appreciated.

EDIT:

For some reason I was saving the file as '.gzip' instead of '.gz'... So in order to have it work I now have:

$response = $client->call('call', $param);
$content = base64_decode($response);
$filename = "output_zip.gz";
if (!$handle = fopen($filename, 'w')) {
    echo "Cannot open file ($filename)";
    exit;
}

if (fwrite($handle, $content) === FALSE) {
  echo "Cannot write to file ($filename)";
  exit;
}
fclose($handle);
echo system("gzip -d $filename");
Was it helpful?

Solution

(Edited based on the comments)

If the return value is base64-encoded, you need to base64-decode it before you write it to the file. Alternatively you could write it out to a file which you then base64-decode to another file before trying to open it, but that seems a bit pointless compared with just decoding it when you first get it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top