Browse Source

le download et en place et fonctionnel

master
Cabillot Julien 6 years ago
parent
commit
2c64e95eba
4 changed files with 51 additions and 13 deletions
  1. 12
      controller/download.php
  2. 9
      include/config.php
  3. 35
      lib/Download.php
  4. 8
      root/index.php

12
controller/download.php

@ -0,0 +1,12 @@
<?php
function getDownload()
{
if (!isset($_GET['myurl'])) {
echo 'pas de get';
exit();
}
$premInfos = PremiumizeMe::getLink($_GET['myurl']);
$result = Download::get($premInfos['location'], $premInfos['filename']);
}

9
include/config.php

@ -5,9 +5,12 @@ define('DB_RWPASS', 'Rinhal3SwefVowsEj0');
define('DB_SERVER', '192.168.122.2');
define('DB_COLL', 'mydl');
/**
* Defini le repertoire temporaire ou seront stocke les downloads
*/
define('DOWNLOADDIR', dirname(__FILE__).'/../download');
include dirname(__FILE__).'/../lib/DbMongo.php';
include dirname(__FILE__).'/../lib/Download.php';
include dirname(__FILE__).'/../lib/PremiumizeMe.php';
include dirname(__FILE__).'/../lib/Stream.php';
?>
include dirname(__FILE__).'/../lib/Stream.php';

35
lib/Download.php

@ -9,18 +9,37 @@ class Download {
*
* @return array Informations sur le transfert
*/
static function get($url, $out) {
static function get($url) {
set_time_limit(0);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt ($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$res = curl_exec($ch);
curl_close($ch);
preg_match('/^HTTP\/1\.[01] (.*) .*/', $res, $matches);
$retCode = $matches[1];
preg_match('/Content-Length: (.*)/', $res, $matches);
$retLenght = $matches[1];
preg_match("/Content-Disposition: attachment; filename=\"(.*)\"; filename\*=UTF-8\'\'(.*)/", $res, $matches);
$retFilename = $matches[1];
unset($matches);
set_time_limit(0);
$fp = fopen($out, 'w+');//This is the file where we save the information
$ch = curl_init($url);//Here is the file we are downloading, replace spaces with %20
curl_setopt($ch, CURLOPT_FILE, $fp); // write curl response to file
$fp = fopen(DOWNLOADDIR.DIRECTORY_SEPARATOR.$retFilename, 'w+');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch); // get curl response
curl_setopt ($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_exec($ch);
$retour = curl_getinfo($ch);
curl_close($ch);
fclose($fp);
return $retour;
}
}
//var_dump(Download::get('https://dl.sdv.fr/files/0/6/7/rubygem-csscss-1.0.0-1.fc18.src.rpm', 'Archive.zip'));
}

8
root/index.php

@ -2,8 +2,6 @@
include dirname(__FILE__).'/../include/config.php';
include dirname(__FILE__).'/../controller/stream.php';
if (!isset($_GET['action'])) {
echo 'Pas d\'action, exit';
exit;
@ -12,6 +10,12 @@ if (!isset($_GET['action'])) {
switch($_GET['action']) {
case 'stream':
// http://mydl.cabillot.eu/?myurl=https://1fichier.com/?yawxht1b3y
include dirname(__FILE__).'/../controller/stream.php';
getStream();
break;
case 'download':
// http://mydl.cabillot.eu/download/?myurl=https://1fichier.com/?yawxht1b3y
include dirname(__FILE__).'/../controller/download.php';
getDownload();
break;
}
Loading…
Cancel
Save