[英]download git repo using php
I want to download a repository file from github after that the user doing an action. 在用户执行操作之后,我想从github下载存储库文件。 The code will not work as expected.
该代码将无法正常工作。 A
.zip
file is created when the code run but the resulting zip file is blank. 运行代码时会创建一个
.zip
文件,但生成的zip文件为空白。 How I can fix this? 我该如何解决?
$url = "https://github.com/$u/$repo/archive/master.zip";
$ch = curl_init();
$f = fopen(__DIR__.'/master.zip', 'w+');
$opt = [
CURLOPT_URL => $url,
CURLOPT_FILE => $f,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_BINARYTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
];
curl_setopt_array($ch, $opt);
$file = curl_exec($ch);
curl_close($ch);
fclose($f);
Remove CURLOPT_RETURNTRANSFER => true
from your code or put it before CURLOPT_FILE
. 从代码中删除
CURLOPT_RETURNTRANSFER => true
或将其放在CURLOPT_FILE
之前。
This is known interaction as CURLOPT_FILE
depends on CURLOPT_RETURNTRANSFER
being set. 这被称为交互,因为
CURLOPT_FILE
取决于所设置的CURLOPT_RETURNTRANSFER
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.