[英]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.