Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 43 lines (33 sloc) 1.215 kb
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
<?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 }';
}

$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);

?>
Something went wrong with that request. Please try again.