Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class ClassDownload
- {
- public $linkdaup = "";
- public function setLinkdaup($bien){
- $this->linkdaup = $bien;
- }
- public function getLinkdaup()
- {
- return $this->linkdaup;
- }
- public function leech_file($remote_file , $local_file , $kb = 5)
- {
- $return = false;
- if(!file_exists($local_file)){
- $f = @fopen( $remote_file, "r");
- var_dump($http_response_header);
- if (strpos($http_response_header[0], '404') == false)
- {
- $file = @fopen( $local_file, "w");
- if (($f) && ($file))
- {
- while(!feof($f))
- {
- fwrite($file, fread($f, 1024*$kb));
- }
- fclose($file);
- fclose($f);
- $return = true;
- }
- else
- {
- $return = false;
- }
- }
- else
- {
- $return = false;
- }
- }else{
- $return = true;
- }
- return $return;
- }
- public function make_dir($url, $parent_path, $thumuc_url){
- $parse = parse_url($thumuc_url);
- $path = $parse['path'];
- $extract = explode('/', $path);
- $subdirname = "";
- for ($i = 0; $i < count($extract); $i++) {
- $subdirname = $subdirname . '/' . $extract[$i];
- if(!is_dir($parent_path. '/' . $subdirname)){
- mkdir($parent_path. '/' . $subdirname, 0777);
- }
- }
- return $parent_path . $subdirname . '/';
- }
- public function flushx (){
- echo(str_repeat(' ',1));
- // check that buffer is actually set before flushing
- if (ob_get_length()){
- @ob_flush();
- @flush();
- @ob_end_flush();
- }
- @ob_start();
- }
- function ClassDownload($linkvideo, $thumuc){
- header('Content-Type: text/html; charset=utf-8');
- set_time_limit(0);
- ini_set('display_errors', 1);
- ignore_user_abort(true);
- error_reporting(E_ALL && ~E_NOTICE);
- if (!function_exists('fopen'))
- {
- echo 'Function fopen() has been disable.';
- exit;
- }
- if (!function_exists('feof'))
- {
- echo 'Function feof() has been disable.';
- exit;
- }
- if (!function_exists('fread'))
- {
- echo 'Function fread() has been disable.';
- exit;
- }
- if (!function_exists('fwrite'))
- {
- echo 'Function fwrite() has been disable.';
- exit;
- }
- if (!function_exists('fclose'))
- {
- echo 'Function fclose() has been disable.';
- exit;
- }
- $video_url = $linkvideo;
- $thumuc_url = $thumuc;
- if(!empty($video_url)){
- $basedir = '/var/www/Public/football/videos/clip';
- $dir = $basedir;
- $dir = $this->make_dir($video_url, $dir, $thumuc_url);
- //echo "<br>Xem thu: " .$dir. "<br>";
- if(!$this->leech_file($video_url , $dir.urldecode(basename($video_url))))
- {
- //echo "<span style='color:red;'>-->Không thể ghi ảnh ".$dir.urldecode(basename($video_url))." hoặc mở file {$video_url} trên url</span></br>";
- //echo "<br>Link video da up: " . $dir.urldecode(basename($video_url)) . "<br>";
- $tinh = $dir.urldecode(basename($video_url));
- $this->setLinkdaup($tinh);
- }else{
- //echo "<span style='color:green;'>-->Tải ảnh về ".$dir.urldecode(basename($video_url))." thành công!</span></br>";
- //echo "<br>Link video da up: " . $dir.urldecode(basename($video_url)) . "<br>";
- $tinh = $dir.urldecode(basename($video_url));
- $this->setLinkdaup($tinh);
- }
- }
- $this->flushx ();
- }
- }
- /*
- $linkvideogoc = "http://img.tamtay.vn/files/photo2/2010/12/9/13/675319/4d0077c4_521c4544_1291831790-bong-da-vn39.jpg";
- $down = new ClassDownload($linkvideogoc);
- echo "<br> Link goc: " . $linkvideogoc;
- echo "<br> Link anh da up: " . $down->getLinkdaup();
- */
- ?>
Add Comment
Please, Sign In to add comment