public function serverDownload()
 {
     $uuid = 'download_' . $this->in['uuid'];
     if ($this->in['type'] == 'percent') {
         //获取下载进度
         //show_json($_SESSION[$uuid]);
         if (isset($_SESSION[$uuid])) {
             $info = $_SESSION[$uuid];
             $result = array('uuid' => $this->in['uuid'], 'length' => (int) $info['length'], 'size' => (int) filesize($info['path']), 'time' => mtime());
             show_json($result);
         } else {
             show_json('', false);
         }
     } else {
         if ($this->in['type'] == 'remove') {
             //取消下载;文件被删掉则自动停止
             del_file($_SESSION[$uuid]['path']);
             unset($_SESSION[$uuid]);
             show_json('', false);
         }
     }
     //下载
     $save_path = _DIR($this->in['save_path']);
     if (!is_writeable($save_path)) {
         show_json($this->L['no_permission_write'], false);
     }
     $url = rawurldecode($this->in['url']);
     $header = url_header($url);
     if (!$header) {
         show_json($this->L['download_error_exists'], false);
     }
     $save_path = $save_path . urldecode($header['name']);
     if (!checkExt($save_path)) {
         //不允许的扩展名
         $save_path = _DIR($this->in['save_path']) . date() . '.txt';
     }
     $save_path = get_filename_auto(iconv_system($save_path));
     $save_path_temp = $save_path . '.downloading';
     session_start();
     $_SESSION[$uuid] = array('length' => $header['length'], 'path' => $save_path_temp);
     session_write_close();
     if (file_download_this($url, $save_path_temp)) {
         if (@rename($save_path_temp, $save_path)) {
             //下载完后重命名
             $name = get_path_this(iconv_app($save_path));
             show_json($this->L['download_success'], true, $name);
         } else {
             show_json($this->L['download_error_create'], false);
         }
     } else {
         show_json($this->L['download_error_create'], false);
     }
 }
Ejemplo n.º 2
0
 public function serverDownload()
 {
     if ($_SERVER['HTTP_REFERER'] != $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]) {
         if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
             $uuid = 'download_' . $this->in['uuid'];
             if ($this->in['type'] == 'percent') {
                 //Get the download progress
                 //show_json($_SESSION[$uuid]);
                 if (isset($_SESSION[$uuid])) {
                     $info = $_SESSION[$uuid];
                     $result = array('uuid' => $this->in['uuid'], 'length' => (int) $info['length'], 'size' => (int) filesize($info['path']), 'time' => mtime());
                     show_json($result);
                 } else {
                     show_json('', false);
                 }
             } else {
                 if ($this->in['type'] == 'remove') {
                     //Cancel download; files are deleted automatically stops
                     del_file($_SESSION[$uuid]['path']);
                     unset($_SESSION[$uuid]);
                     show_json('', false);
                 }
             }
             //download
             $save_path = _DIR($this->in['save_path']);
             if (!is_writeable($save_path)) {
                 show_json($this->L['no_permission_write'], false);
             }
             $url = rawurldecode($this->in['url']);
             $header = url_header($url);
             if (!$header) {
                 show_json($this->L['download_error_exists'], false);
             }
             $save_path = $save_path . urldecode($header['name']);
             if (!checkExt($save_path)) {
                 //Allowed extension
                 $save_path = _DIR($this->in['save_path']) . date() . '.txt';
             }
             $save_path = get_filename_auto(iconv_system($save_path));
             $save_path_temp = $save_path . '.downloading';
             session_start();
             $_SESSION[$uuid] = array('length' => $header['length'], 'path' => $save_path_temp);
             session_write_close();
             if (file_download_this($url, $save_path_temp)) {
                 if (@rename($save_path_temp, $save_path)) {
                     //After downloading rename
                     $name = get_path_this(iconv_app($save_path));
                     show_json($this->L['download_success'], true, $name);
                 } else {
                     show_json($this->L['download_error_create'], false);
                 }
             } else {
                 show_json($this->L['download_error_create'], false);
             }
         }
     } else {
         header('Location: 403.php');
     }
 }