繁体   English   中英

在php下载git master repository

[英]Download git master repository in php

我想将git master.zip下载到php代码中的目录。 我正在使用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_url_fopen设置为On ,则可以使用file_get_contents() 在这种情况下不需要卷曲。 我使用以下方法成功下载了master.zip的一个存储库的master.zip

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM