我正在使用cURL从GitLab使用其API下载存储库。所有这些都是使用PHP完成的。代码如下:使用GitLab的API下载了GitLab存档库似乎已损坏
$zipResource = fopen('archive.zip', 'w');
$ch = curl_init("http://example.com/api/v3/projects");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("PRIVATE-TOKEN: private_token_goes_here"));
curl_setopt($ch, CURLOPT_URL, "http://example.com/api/v3/projects/64/repository/archive");
curl_setopt($ch, CURLOPT_FILE, $zipResource);
curl_exec($ch);
curl_close($ch);
简要概述:创建一个空的zip文件。连接到服务器,获取存档并将其写入zip文件。
存档出现在服务器上,我可以下载它,当我双击它时,我可以解压缩它,所有文件都在那里,一切似乎都是按顺序的。
然而,当我尝试使用终端以下错误弹出来将它解压缩:
Archive: archive.ZIP
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
什么我试过到目前为止是:
设置标头,"Content-type: application/zip"
。将标题设置为"Content-Transfer-Encoding: Binary"
(归档文件类型为'wb' //binary
)或"Content-type: application/octet-stream"
等等。最终结果总是相同的,这意味着当试图解压缩压缩文件时会出现上述错误。
我只能假设我要么没有正确使用cURL,没有正确设置标题,或者他们的API出现问题(极不可能)。
任何在正确的方向推动非常感谢。
那么这可能是他们的api /后端系统创建zip文件的错误:D – hanshenrik 2015-10-14 09:38:26