Created
September 22, 2020 15:24
-
-
Save smailliwcs/4a278bf58cc84ad49c8306d64e9b108f to your computer and use it in GitHub Desktop.
Simple PHP proxy
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 | |
function download($url) { | |
$curl = curl_init($url); | |
curl_setopt_array($curl, [ | |
CURLOPT_FOLLOWLOCATION => true, | |
CURLOPT_RETURNTRANSFER => true | |
]); | |
$data = curl_exec($curl); | |
curl_close($curl); | |
return $data; | |
} | |
function getFileName($url) { | |
$fileName = basename(parse_url($url, PHP_URL_PATH)); | |
return empty($fileName) ? "data" : $fileName; | |
} | |
$url = trim($_GET["url"]); | |
if (!empty($url)) { | |
$data = gzencode(download($url)); | |
header("Content-Type: application/gzip"); | |
header(sprintf("Content-Length: %d", strlen($data))); | |
header(sprintf("Content-Disposition: attachment; filename=%s.gz", getFileName($url))); | |
print($data); | |
return; | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Proxy</title> | |
</head> | |
<body> | |
<form action="<?= $_SERVER["SCRIPT_NAME"] ?>" method="get"> | |
<label> | |
URL: | |
<input type="text" name="url" size="50" /> | |
</label> | |
<input type="submit" value="Download" /> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment