我正在尝试使用 curl 和 php 下载 gzip 文件并将其保存在指定位置。下面是我正在使用的代码,但每次它都保存一个空文件,尽管它下载的 gzip 文件是正确的
$file_zip = 'abc.gz'
$fp = fopen("$file_zip", "w");
$request = curl_init();
$headers = array('Content-type: application/x-gzip','Connection: Close');
curl_setopt($request, CURLOPT_URL, $url);
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($request, CURLOPT_TIMEOUT, 0);
curl_setopt($request, CURLOPT_CONNECTTIMEOUT,0);
curl_setopt($request, CURLOPT_HTTPHEADER,$headers);
curl_setopt($request, CURLOPT_FAILONERROR, true);
curl_setopt($request, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($request, CURLOPT_AUTOREFERER, true);
curl_setopt($request, CURLOPT_BINARYTRANSFER,true);
curl_setopt($request, CURLOPT_FILE, $fp);
$zipFile = curl_exec($request);