thieumao

ClassDownload.php

Feb 24th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.50 KB | None | 0 0
  1. <?php
  2.  
  3. class ClassDownload
  4. {
  5.  
  6.     public $linkdaup = "";
  7.  
  8.     public function setLinkdaup($bien){
  9.         $this->linkdaup = $bien;
  10.     }
  11.  
  12.     public function getLinkdaup()
  13.     {
  14.         return $this->linkdaup;
  15.     }
  16.  
  17.     public function leech_file($remote_file , $local_file , $kb = 5)
  18.     {
  19.         $return = false;
  20.         if(!file_exists($local_file)){
  21.             $f = @fopen( $remote_file, "r");
  22.             var_dump($http_response_header);
  23.             if (strpos($http_response_header[0], '404') == false)
  24.             {
  25.                 $file = @fopen( $local_file, "w");
  26.                 if (($f) && ($file))
  27.                 {
  28.                     while(!feof($f))
  29.                     {
  30.                         fwrite($file, fread($f, 1024*$kb));
  31.                     }
  32.                     fclose($file);
  33.                     fclose($f);
  34.                     $return = true;
  35.                 }
  36.                 else
  37.                 {
  38.                     $return = false;
  39.                 }
  40.             }
  41.             else
  42.             {
  43.                 $return = false;
  44.             }
  45.         }else{
  46.             $return = true;
  47.         }
  48.         return $return;
  49.     }
  50.  
  51.     public function make_dir($url, $parent_path, $thumuc_url){
  52.        
  53.         $parse = parse_url($thumuc_url);
  54.         $path = $parse['path'];
  55.         $extract = explode('/', $path);
  56.         $subdirname = "";
  57.         for ($i = 0; $i < count($extract); $i++) {
  58.             $subdirname = $subdirname . '/' . $extract[$i];
  59.             if(!is_dir($parent_path. '/' . $subdirname)){
  60.                 mkdir($parent_path. '/' . $subdirname, 0777);
  61.             }
  62.         }
  63.  
  64.         return $parent_path .  $subdirname . '/';
  65.  
  66.     }
  67.  
  68.  
  69.     public  function flushx (){
  70.         echo(str_repeat(' ',1));
  71.         // check that buffer is actually set before flushing
  72.         if (ob_get_length()){
  73.             @ob_flush();
  74.             @flush();
  75.             @ob_end_flush();
  76.         }
  77.         @ob_start();
  78.     }
  79.  
  80.     function ClassDownload($linkvideo, $thumuc){
  81.         header('Content-Type: text/html; charset=utf-8');
  82.         set_time_limit(0);
  83.         ini_set('display_errors', 1);
  84.         ignore_user_abort(true);
  85.         error_reporting(E_ALL && ~E_NOTICE);
  86.         if (!function_exists('fopen'))
  87.         {
  88.             echo 'Function fopen() has been disable.';
  89.             exit;
  90.         }
  91.         if (!function_exists('feof'))
  92.         {
  93.             echo 'Function feof() has been disable.';
  94.             exit;
  95.         }
  96.         if (!function_exists('fread'))
  97.         {
  98.             echo 'Function fread() has been disable.';
  99.             exit;
  100.         }
  101.         if (!function_exists('fwrite'))
  102.         {
  103.             echo 'Function fwrite() has been disable.';
  104.             exit;
  105.         }
  106.         if (!function_exists('fclose'))
  107.         {
  108.             echo 'Function fclose() has been disable.';
  109.             exit;
  110.         }
  111.  
  112.         $video_url = $linkvideo;
  113.         $thumuc_url = $thumuc;
  114.         if(!empty($video_url)){
  115.             $basedir = '/var/www/Public/football/videos/clip';
  116.             $dir = $basedir;
  117.             $dir = $this->make_dir($video_url, $dir, $thumuc_url);
  118.             //echo "<br>Xem thu: " .$dir. "<br>";
  119.  
  120.             if(!$this->leech_file($video_url , $dir.urldecode(basename($video_url))))
  121.             {
  122.                 //echo "<span style='color:red;'>-->Kh&#244;ng th&#7875; ghi &#7843;nh ".$dir.urldecode(basename($video_url))." ho&#7863;c m&#7903; file {$video_url} tr&#234;n url</span></br>";
  123.                 //echo "<br>Link video da up: " . $dir.urldecode(basename($video_url)) . "<br>";
  124.                 $tinh = $dir.urldecode(basename($video_url));
  125.                 $this->setLinkdaup($tinh);
  126.             }else{
  127.                 //echo "<span style='color:green;'>-->T&#7843;i &#7843;nh v&#7873; ".$dir.urldecode(basename($video_url))." th&#224;nh c&#244;ng!</span></br>";
  128.                 //echo "<br>Link video da up: " . $dir.urldecode(basename($video_url)) . "<br>";
  129.                 $tinh = $dir.urldecode(basename($video_url));
  130.                 $this->setLinkdaup($tinh);
  131.             }
  132.         }
  133.         $this->flushx ();
  134.     }
  135.  
  136. }
  137.  
  138. /*
  139.  $linkvideogoc = "http://img.tamtay.vn/files/photo2/2010/12/9/13/675319/4d0077c4_521c4544_1291831790-bong-da-vn39.jpg";
  140.  $down = new ClassDownload($linkvideogoc);
  141.  echo "<br> Link goc: " . $linkvideogoc;
  142.  echo "<br> Link anh da up: " . $down->getLinkdaup();
  143.  */
  144.  
  145. ?>
Add Comment
Please, Sign In to add comment