-
Notifications
You must be signed in to change notification settings - Fork 1
/
get.php
44 lines (33 loc) · 1.1 KB
/
get.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
$gist_id = $_REQUEST["id"]; // Replace with the Gist ID you want to fetch
$target_filename = "index.html"; // Replace with the filename you want to retrieve
$api_url = "https://api.github.com/gists/$gist_id";
$curl = curl_init($api_url);
$headers = [
'User-Agent: Codes20', // Replace with your app name
'Content-Type: application/json',
];
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($status == 200) {
$gist = json_decode($response, true);
$fileExists = false;
foreach ($gist['files'] as $filename => $file) {
if ($filename === $target_filename) {
$fileExists = true;
//echo "File Name: $filename\n";
//echo "Content:\n";
echo $file['content'];
//echo "\n\n";
}
}
if (!$fileExists) {
echo "File with the filename '$target_filename' not found in the Gist.";
}
} else {
echo "Failed to fetch Gist. HTTP Status Code: $status";
}
?>