This repository has been archived by the owner on Jun 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 279
/
proxy.php
51 lines (40 loc) · 1.47 KB
/
proxy.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
45
46
47
48
49
50
51
<?php
$url = filter_var($_POST['url'], FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED);
if (!$url || !preg_match("/^https?:/i", $url)) {
echo '{ "result": "Invalid URL. Please check your URL and try again.", "error": true }';
return;
}
$parsed_url = parse_url($url);
$scheme = strtolower($parsed_url['scheme']);
if (array_key_exists('port', $parsed_url) || ($scheme !== "http" && $scheme !== "https")) {
echo '{ "result": "Invalid URL - Please check your URL and try again.", "error": true }';
return;
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($data === false) {
echo '{ "result": "Unable to parse URL. Please check your URL and try again.", "error": true }';
return;
}
$contentLength = intval($info['download_content_length']);
$status = intval($info['http_code']);
if ($status >= 400) {
echo '{ "result": "URL returned bad status code ' . $status . '.", "error": true }';
return;
}
if ($contentLength >= 52428800) {
echo '{ "result": "URL content length greater than 10 megs (' . $contentLength . '). Validation not available for files this large.", "responseCode": "1" }';
return;
}
$response = new StdClass();
$response->status = $status;
$response->length = $contentLength;
$response->url = $info['url'];
$response->content = $data;
echo json_encode($response);
?>