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
function upload_chunk($fileInput, $path = './', $temp_path)
{
    global $config, $L;
    $file = $_FILES[$fileInput];
    $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
    $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 1;
    if (!isset($file)) {
        show_json($L['upload_error_null'], false);
    }
    $file_name = iconv_system($file['name']);
    if ($chunks > 1) {
        //并发上传,不一定有前后顺序
        $temp_file_pre = $temp_path . md5($temp_path . $file_name) . '.part';
        if (get_filesize($file['tmp_name']) == 0) {
            show_json($L['upload_success'], false, 'chunk_' . $chunk . ' error!');
        }
        if (move_uploaded_file($file['tmp_name'], $temp_file_pre . $chunk)) {
            $done = true;
            for ($index = 0; $index < $chunks; $index++) {
                if (!file_exists($temp_file_pre . $index)) {
                    $done = false;
                    break;
                }
            }
            if (!$done) {
                show_json($L['upload_success'], true, 'chunk_' . $chunk . ' success!');
            }
            $save_path = $path . $file_name;
            $out = fopen($save_path, "wb");
            if ($done && flock($out, LOCK_EX)) {
                for ($index = 0; $index < $chunks; $index++) {
                    if (!($in = fopen($temp_file_pre . $index, "rb"))) {
                        break;
                    }
                    while ($buff = fread($in, 4096)) {
                        fwrite($out, $buff);
                    }
                    fclose($in);
                    unlink($temp_file_pre . $index);
                }
                flock($out, LOCK_UN);
                fclose($out);
            }
            show_json($L['upload_success'], true, iconv_app($save_path));
        } else {
            show_json($L['move_error'], false);
        }
    }
    //正常上传
    $save_path = get_filename_auto($path . $file_name);
    //自动重命名
    if (move_uploaded_file($file['tmp_name'], $save_path)) {
        show_json($L['upload_success'], true, iconv_app($save_path));
    } else {
        show_json($L['move_error'], false);
    }
}
Ejemplo n.º 3
0
 private function zip($zip_path)
 {
     if (!isset($zip_path)) {
         show_json($this->L['share_not_download_tips'], false);
     }
     load_class('pclzip');
     ini_set('memory_limit', '2028M');
     //2G;
     $zip_list = json_decode($this->in['list'], true);
     $list_num = count($zip_list);
     for ($i = 0; $i < $list_num; $i++) {
         $zip_list[$i]['path'] = _DIR_CLEAR($this->path . $this->_clear($zip_list[$i]['path']));
     }
     //指定目录
     if ($list_num == 1) {
         $path_this_name = get_path_this($zip_list[0]['path']);
     } else {
         $path_this_name = get_path_this(get_path_father($zip_list[0]['path']));
     }
     $zipname = $zip_path . $path_this_name . '.zip';
     $zipname = get_filename_auto($zipname, date(' h.i.s'));
     $files = array();
     for ($i = 0; $i < $list_num; $i++) {
         $files[] = $zip_list[$i]['path'];
     }
     $remove_path_pre = get_path_father($zip_list[0]['path']);
     $archive = new PclZip($zipname);
     $v_list = $archive->create(implode(',', $files), PCLZIP_OPT_REMOVE_PATH, $remove_path_pre);
     return iconv_app($zipname);
 }
Ejemplo n.º 4
0
function _upload($tmp_name, $size, $save_path)
{
    global $L;
    $save_path = get_filename_auto($save_path);
    if (move_uploaded_file($tmp_name, $save_path)) {
        return array('code' => true, 'data' => $L['upload_success'], 'path' => $save_path);
    } else {
        return array('code' => fasle, 'data' => $L['move_error']);
    }
}
Ejemplo n.º 5
0
 public function zip()
 {
     load_class('pclzip');
     ini_set('memory_limit', '2028M');
     //2G;
     $zip_list = json_decode($this->in['list'], true);
     $list_num = count($zip_list);
     for ($i = 0; $i < $list_num; $i++) {
         $zip_list[$i]['path'] = _DIR($zip_list[$i]['path']);
     }
     $basic_path = get_path_father($zip_list[0]['path']);
     if ($list_num == 1) {
         $path_this_name = get_path_this($zip_list[0]['path']);
         $zipname = $basic_path . $path_this_name . '.zip';
     } else {
         $path_this_name = get_path_this(get_path_father($zip_list[0]['path']));
         $zipname = $basic_path . $path_this_name . '.zip';
     }
     $zipname = get_filename_auto($zipname);
     if (!is_writeable($basic_path)) {
         show_json("{$zipname}" . $this->L['no_permission_write'], false);
     } else {
         $files = array();
         for ($i = 0; $i < $list_num; $i++) {
             $files[] = $zip_list[$i]['path'];
         }
         $archive = new PclZip($zipname);
         $v_list = $archive->create(implode(',', $files), PCLZIP_OPT_REMOVE_PATH, $basic_path);
         if ($v_list == 0) {
             show_json("Error : " . $archive->errorInfo(true), false);
         }
         $info = $this->L['zip_success'] . $this->L['size'] . ":" . size_format(filesize($zipname));
         show_json($info);
     }
 }
Ejemplo n.º 6
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');
     }
 }