Download latest GitHub release

前端 未结 8 1872
心在旅途
心在旅途 2020-12-03 03:36

I\'d like to have \"Download Latest Version\" button on my website which would represent the link to the latest release (stored at GitHub Releases

8条回答
  •  無奈伤痛
    2020-12-03 04:05

    If you using PHP try follow code:

    function getLatestTagUrl($repository, $default = 'master') {
        $file = @json_decode(@file_get_contents("https://api.github.com/repos/$repository/tags", false,
            stream_context_create(['http' => ['header' => "User-Agent: Vestibulum\r\n"]])
        ));
    
        return sprintf("https://github.com/$repository/archive/%s.zip", $file ? reset($file)->name : $default);
    }
    

    Function usage example

    echo 'Download';
    

提交回复
热议问题