Skip to content

Instantly share code, notes, and snippets.

@smailliwcs
Created September 22, 2020 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smailliwcs/4a278bf58cc84ad49c8306d64e9b108f to your computer and use it in GitHub Desktop.
Save smailliwcs/4a278bf58cc84ad49c8306d64e9b108f to your computer and use it in GitHub Desktop.
Simple PHP proxy
<?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