So I’ve been working on this script for the past 3 days for my company to get a log file automatically sent to my Github repository. I expected this to be quite easy actually (boy was I mistaken) and have no idea how to use the API to send over information. After doing quite a bit of research, I found another user’s post here:
However, this states to require a sha.txt file, which I don’t understand how to get. According to the code another user provided, you have to already have the file in your repository (or maybe I’m misunderstanding). How do I get a sha file for something that doesn’t exist? Can someone please assist me?
For clarity, I’m using my companies cpanel > phpmyadmin section to utilize the script (so shell_exec and generally shell_exec commands are off the table). Here is the transfer file that I’m speaking about:
<?php $file_git = "wall.jpg"; $data_git = array( 'sha'=>file_get_contents("sha.txt"), 'message'=>'image', 'content'=> base64_encode($file_git), 'committer'=> array( 'name'=>'Jacob', 'email' => 'email@example.com' ) ); $data_string_git = json_encode($data_git); $ch_git = curl_init('https://api.github.com/repos/YOUR_REPO/contents/wall.jpg'); curl_setopt($ch_git, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($ch_git, CURLOPT_POSTFIELDS, $data_string_git); curl_setopt($ch_git, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch_git, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 YaBrowser/220.127.116.114 Yowser/2.5 Safari/537.36', 'Authorization: token PLACE_YOUR_PERSONAL_TOKEN_HERE' )); $result_git = curl_exec($ch_git); echo $result_git; $p_git = json_decode($result_git); file_put_contents("sha.txt",$p_git->content->sha); ?>
TLDR; I’m trying to get an example or assistance on how to pass a file through php script to my github repository.