Created
July 12, 2019 17:03
-
-
Save afragen/a1fd48dd705fb26e3574954e45b1d895 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$config = [ | |
//'token' => '012345', | |
'repo' => 'satispress', | |
'username' => 'cedaro', | |
]; | |
$file_location = 'releases/'; | |
$file_name = 'test.zip'; | |
//$file = 'https://api.github.com/repos/' . $config['username'] . '/' . $config['repo'] . '/releases . '?access_token=' . $config['token']; | |
$file = 'https://api.github.com/repos/' . $config['username'] . '/' . $config['repo'] . '/releases'; | |
$headers = [ | |
'User-Agent: ' . $config['username'], | |
'Content-type: application/vnd.github.3.raw', | |
//'Authorization: token ' . $config['token'], | |
//'Accept: application/octet-stream', | |
]; | |
$ch = curl_init(); | |
//curl_setopt( $ch, CURLOPT_BINARYTRANSFER, true ); | |
curl_setopt($ch, CURLOPT_URL, $file); | |
curl_setopt($ch, CURLOPT_USERNAME, $config['username']); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
//curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
//if (! empty($data)) { | |
// $fp = fopen($file_location . $file_name, 'w+'); | |
// fwrite($fp, $data); | |
// fclose($fp); | |
//} | |
// | |
//header('Pragma: public'); | |
//header('Expires: 0'); | |
//header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); | |
//header('Cache-Control: public'); | |
//header('Content-Description: File Transfer'); | |
//header('Content-Type: application/octet-stream'); | |
//header('Content-Disposition: attachment; filename=' . $file_name); | |
//header('Content-Transfer-Encoding: binary'); | |
//header('Content-Length: ' . filesize($file_location . $file_name)); | |
//header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($file_location . //$file_name))); | |
//ob_end_flush(); | |
//readfile($file); | |
if (! empty($data)) { | |
$response = json_decode($data); | |
foreach ($response as $assets) { | |
$arr_assets[$assets->name] = $assets->assets[0]->browser_download_url; | |
} | |
return $arr_assets; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment