来自 SOAP 的文件,如何保存?

发布于 2024-07-17 00:49:07 字数 882 浏览 8 评论 0原文

我正在与客户合作从他们的网络服务获取 gzip。 我能够通过以下调用得到响应:

$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;
}

现在,当我尝试写入一个文件(例如“test.gzip”)时,我之后无法打开它......很可能是因为我做了一些可怕的错误。 任何见解将不胜感激。

编辑:

出于某种原因,我将文件保存为“.gzip”而不是“.gz”...所以为了让它工作,我现在有:

$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");

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");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山色无中 2024-07-24 00:49:08

(根据注释编辑)

如果返回值是base64编码的,则需要在将其写入文件之前对其进行base64解码。 或者,您可以将其写入一个文件,然后在尝试打开它之前将其进行 base64 解码为另一个文件,但这与您第一次获取它时仅对其进行解码相比似乎有点毫无意义。

(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文