public function fileGet() { $filename = _DIR($this->in['filename']); if (!is_readable($filename)) { show_json($this->L['no_permission_read'], false); } if (filesize($filename) >= 1024 * 1024 * 20) { show_json($this->L['edit_too_big'], false); } $filecontents = file_get_contents($filename); //文件内容 $charset = get_charset($filecontents); if ($charset != '' || $charset != 'utf-8') { $filecontents = mb_convert_encoding($filecontents, 'utf-8', $charset); } $data = array('ext' => get_path_ext($filename), 'name' => iconv_app(get_path_this($filename)), 'filename' => rawurldecode($this->in['filename']), 'charset' => $charset, 'content' => $filecontents); show_json($data); }
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); } }
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); } }
public function fileGet() { $name = $this->_clear($this->in['filename']); $filename = $this->share_path . $name; if (filesize($filename) >= 1024 * 1024 * 20) { show_json($this->L['edit_too_big'], false); } $filecontents = file_get_contents($filename); //文件内容 $charset = $this->_get_charset($filecontents); if ($charset != '' || $charset != 'utf-8') { $filecontents = mb_convert_encoding($filecontents, 'utf-8', $charset); } $data = array('ext' => get_path_ext($name), 'name' => iconv_app($name), 'filename' => $name, 'charset' => $charset, 'content' => $filecontents); show_json($data); }
function path_search($path, $search, $is_content = false, $file_ext = '', $is_case = false) { $ext_arr = explode("|", $file_ext); recursion_dir($path, $dirs, $files, -1, 0); $strpos = 'stripos'; //是否区分大小写 if ($is_case) { $strpos = 'strpos'; } $filelist = array(); $folderlist = array(); foreach ($files as $f) { $ext = get_path_ext($f); $path_this = get_path_this($f); if ($file_ext != '' && !in_array($ext, $ext_arr)) { continue; } //文件类型不在用户限定内 if ($strpos($path_this, $search) !== false) { //搜索文件名;搜到就返回;搜不到继续 $filelist[] = file_info($f); continue; } if ($is_content && is_file($f)) { $fp = fopen($f, "r"); $content = @fread($fp, filesize($f)); fclose($fp); if ($strpos($content, $search) !== false) { $filelist[] = file_info($f); } } } if ($file_ext == '') { //没限定扩展名则才搜索文件夹 foreach ($dirs as $f) { $path_this = get_path_this($f); if ($strpos($path_this, $search) !== false) { $folderlist[] = array('name' => iconv_app(get_path_this($f)), 'path' => iconv_app(get_path_father($f))); } } } return array('folderlist' => $folderlist, 'filelist' => $filelist); }
public function pathPast() { session_start(); //re start $info = ''; $data = array(); $clipboard = json_decode($_SESSION['path_copy'], true); if (count($clipboard) == 0) { show_json($data, false, $this->L['clipboard_null']); } $copy_type = $_SESSION['path_copy_type']; $path_past = $this->path; if (!is_writable($path_past)) { show_json($data, false, $this->L['no_permission_write']); } $list_num = count($clipboard); if ($list_num == 0) { show_json($data, false, $this->L['clipboard_null']); } for ($i = 0; $i < $list_num; $i++) { $path_copy = _DIR($clipboard[$i]['path']); $filename = get_path_this($path_copy); $filename_out = iconv_app($filename); if (!file_exists($path_copy) && !is_dir($path_copy)) { $info .= $path_copy . "<li>{$filename_out}'.{$this->L}['copy_not_exists'].'</li>"; continue; } if ($clipboard[$i]['type'] == 'folder') { if ($path_copy == substr($path_past, 0, strlen($path_copy))) { $info .= "<li style='color:#f33;'>{$filename_out}'.{$this->L}['current_has_parent'].'</li>"; continue; } } if ($copy_type == 'copy') { if ($clipboard[$i]['type'] == 'folder') { copy_dir($path_copy, $path_past . $filename); } else { copy($path_copy, $path_past . $filename); } } else { if ($cute_list[$i]['type'] == 'folder') { rename($path_copy, $path_past . $filename . '/'); } else { rename($path_copy, $path_past . $filename); } } $data[] = iconv_app($filename); } if ($copy_type == 'copy') { $info = $this->L['past_success'] . $info; } else { $_SESSION['path_copy'] = json_encode(array()); $_SESSION['path_copy_type'] = ''; $info = $this->L['cute_past_success'] . $info; } show_json($data, true, $info); }
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'); } }