Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
下载php中的git主存储库_Php_Git_Curl - Fatal编程技术网

下载php中的git主存储库

下载php中的git主存储库,php,git,curl,Php,Git,Curl,我想用php代码将git master.zip下载到一个目录中。我正在使用cURL下载它,并且我的代码可以正常工作,所以这个方面可以正常工作。我想知道如何从一些主URL获取正确的文件,例如 https://github.com/{group}/{project}/archive/master.zip 我收到的文件只有1字节的信息,我想知道哪里出了问题。这是我下载时使用的代码 <?php //just an example repository $url = 'https://github

我想用php代码将git master.zip下载到一个目录中。我正在使用cURL下载它,并且我的代码可以正常工作,所以这个方面可以正常工作。我想知道如何从一些主URL获取正确的文件,例如

https://github.com/{group}/{project}/archive/master.zip
我收到的文件只有1字节的信息,我想知道哪里出了问题。这是我下载时使用的代码

<?php
//just an example repository
$url = 'https://github.com/octocat/Spoon-Knife/archive/master.zip';

$fh = fopen('master.zip', 'w');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_FILE, $fh); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // this will follow redirects
curl_exec($ch);

print 'Attempting download of '.$url.'<br />';
if(curl_error($ch) == '')
    $errors = '<u>none</u>';
else
    $errors = '<u>'.curl_error($ch).'</u>';
print 'cURL Errors : '.$errors;

curl_close($ch);

fclose($fh);
?>


谢谢。

如果在
php.ini
allow\u url\u fopen
设置为
On
,您只需使用
file\u get\u contents()
。这种情况下不需要卷曲。我使用以下工具成功下载了我的一个存储库的
master.zip

file_put_contents("master.zip", 
    file_get_contents("https://github.com/metashock/Hexdump/archive/master.zip")
);

我收到了整个FileTrange,我也在测试存储库中收到了该文件,但不是在我将从中获取的实际存储库中。你知道问题可能是什么吗?很难说没有真正体验过问题,首先是
文件\u get\u contents()
有什么问题<这里不需要code>curl,我意识到这可能是文件大小的问题。cURL是否只允许对文件传输进行限制?是的,我已正确设置了php.ini文件。我意识到这可能是因为我正试图从私有存储库获取master.zip。我没有对存储库的控制权,所以有没有办法用私有存储库做到这一点?我猜私有意味着私有;)