Last active
December 16, 2015 05:09
-
-
Save ssut/5382323 to your computer and use it in GitHub Desktop.
SkyDrive direct download.. (Original: http://corpuscollectum.wordpress.com/2011/07/12/skydrive-direct-download-link-hotlink/, Procedure-Oriented)
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 | |
ini_set('display_error', 1); | |
error_reporting(E_ALL & ~E_NOTICE); | |
class skyDriveDL { | |
// Location | |
private $loc; | |
// File | |
private $file; | |
// Content ID | |
private $cid; | |
// Full location | |
private $fullLocation; | |
// isDebug ? | |
private $debug; | |
public function __construct($id, $file, $debug = false) { | |
$this->loc = $id; | |
$this->file = $file; | |
$this->debug = $debug; | |
$this->cid = preg_replace('/!.+/i', '', $this->loc); | |
$this->fullLocation = sprintf('https://skydrive.live.com/?cid=%s&id=%s', $this->cid, $this->loc); | |
} | |
private function getContent($url) { | |
if(function_exists('file_get_contents') && (bool)ini_get('allow_url_fopen') === true) | |
return file_get_contents($url); | |
elseif(function_exists('curl_init')) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); | |
$content = curl_exec($ch); | |
curl_close($ch); | |
return $content; | |
} | |
} | |
public function getLink($redirect = false) { | |
$content = $this->getContent($this->fullLocation); | |
$enc = preg_replace('/ /i', '%20', $this->file); | |
$enc = preg_replace('/\+/i', '%2B', $enc); | |
$enc = preg_replace('/\(/i', '\(', $enc); | |
$enc = preg_replace('/\)/i', '\)', $enc); | |
$dlmatch = '/(?<="download":")https:[^:]+'; | |
$dlmatch .= $enc; | |
$dlmatch .= '/i'; | |
if(preg_match($dlmatch, $content, $match)) { | |
$out = preg_replace('/\\\\/i', '', $match[0]); | |
if($redirect) { | |
header(sprintf('location: %s', $out)); | |
exit; | |
} | |
return $out; | |
} else return false; | |
} | |
} | |
// Example.... http://localhost/skydrivedl.php?id=blabla&file=blabla.bla ... | |
if($_GET['id'] && $_GET['file']) { | |
$SDL = new skyDriveDL($_GET['id'], $_GET['file']); | |
$result = $SDL->getLink(true); | |
if($result === false) echo 'Cannot download a file ..'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment