예제 #1
0
 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);
 }
예제 #2
0
 /**
  * 权限验证;统一入口检验
  */
 public function authCheck()
 {
     if ($GLOBALS['is_root'] == 1) {
         return;
     }
     if (ACT == 'loginSubmit' || ACT == 'checkCode') {
         return;
     }
     if (!array_key_exists(ST, $this->config['role_setting'])) {
         return;
     } else {
         if (!in_array(ACT, $this->config['role_setting'][ST])) {
             return;
         } else {
             //有权限限制的函数
             $key = ST . ':' . ACT;
             $group = new fileCache($this->config['system_file']['group']);
             $GLOBALS['auth'] = $auth = $group->get($this->user['role']);
             if ($auth[$key] !== 1) {
                 show_json($this->L['no_permission'], false);
             }
             //扩展名限制:新建文件&上传文件&重命名文件&保存文件&zip解压文件
             $check_arr = array('mkfile' => $this->in['path'], 'pathRname' => $this->in['rname_to'], 'fileUpload' => $_FILES['file']['name'], 'fileSave' => $this->in['path']);
             if (array_key_exists(ACT, $check_arr)) {
                 $ext = get_path_ext($check_arr[ACT]);
                 $ext_arr = explode('|', $auth['ext_not_allow']);
                 if (in_array($ext, $ext_arr)) {
                     show_json($this->L['no_permission_ext'], false);
                 }
             }
         }
     }
     return;
 }
 private function path_share()
 {
     $path_hidden = $this->config['setting_system']['path_hidden'];
     $ex_name = explode(',', $path_hidden);
     $userShare = init_controller('userShare');
     $share_list = $userShare->get();
     $list = array('folderlist' => array(), 'filelist' => array(), 'share_list' => $share_list, 'path_type' => "writeable");
     foreach ($share_list as $key => $value) {
         $value['path'] = $key;
         $value['atime'] = '';
         $value['ctime'] = '';
         $value['mode'] = '';
         $value['is_readable'] = 1;
         $value['is_writable'] = 1;
         $value['exists'] = intval(file_exists(_DIR($share_list[$key]['path'])));
         if ($value['type'] == 'file') {
             if (in_array($value['name'], $ex_name)) {
                 continue;
             }
             $value['ext'] = get_path_ext($share_list[$key]['path']);
             $list['filelist'][] = $value;
         } else {
             if (in_array($value['name'], $ex_name)) {
                 continue;
             }
             $list['folderlist'][] = $value;
         }
     }
     return $list;
 }
예제 #4
0
/**
 * 输出、文件下载
 * 默认以附件方式下载;$download为false时则为输出文件
 */
function file_put_out($file, $download = false)
{
    if (!is_file($file)) {
        show_json('not a file!');
    }
    if (!file_exists($file)) {
        show_json('file not exists', false);
    }
    if (!is_readable($file)) {
        show_json('file not readable', false);
    }
    set_time_limit(0);
    ob_clean();
    //清除之前所有输出缓冲 TODO
    $mime = get_file_mime(get_path_ext($file));
    if ($download || strstr($mime, 'application/') && $mime != 'application/x-shockwave-flash') {
        //下载或者application则设置下载头
        $filename = get_path_this($file);
        //解决在IE中下载时中文乱码问题
        if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT']) || preg_match('/Trident/', $_SERVER['HTTP_USER_AGENT'])) {
            if ($GLOBALS['config']['system_os'] != 'windows') {
                //win主机 ie浏览器;中文文件下载urlencode问题
                $filename = str_replace('+', '%20', urlencode($filename));
            }
        }
        header("Content-Type: application/octet-stream");
        header("Content-Disposition: attachment;filename=" . $filename);
    } else {
        //缓存文件
        header('Expires: ' . date('D, d M Y H:i:s', time() + 3600 * 24 * 20) . ' GMT');
        header("Cache-Pragma: public");
        header("Cache-Control: cache, must-revalidate");
        if (isset($_SERVER['If-Modified-Since']) && strtotime($_SERVER['If-Modified-Since']) == filemtime($file)) {
            header('HTTP/1.1 304 Not Modified');
            header('Last-Modified: ' . date('D, d M Y H:i:s', filemtime($file)) . ' GMT');
            //304
            exit;
        } else {
            header('Last-Modified: ' . date('D, d M Y H:i:s', filemtime($file)) . ' GMT', true, 200);
        }
        $etag = '"' . md5(date('D, d M Y H:i:s', filemtime($file))) . '"';
        if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
            header('HTTP/1.1 304 Not Modified');
            header('Etag: ' . $etag);
            exit;
        } else {
            header('Etag: ' . $etag);
        }
    }
    header("X-Powered-By: kodExplorer.");
    header("Content-Type: " . $mime);
    header("Accept-Ranges: bytes");
    $size = get_filesize($file);
    $length = $size;
    // Content length
    $start = 0;
    // Start byte
    $end = $size - 1;
    // End byte
    if (isset($_SERVER['HTTP_RANGE']) || isset($_GET['start'])) {
        //分段请求;视频拖拽
        $c_start = $start;
        $c_end = $end;
        if (isset($_GET['start'])) {
            $c_start = intval($_GET['start']);
        } else {
            //range
            list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
            if (strpos($range, ',') !== false) {
                header('HTTP/1.1 416 Requested Range Not Satisfiable');
                header("Content-Range: bytes {$start}-{$end}/{$size}");
                exit;
            }
            if ($range == '-') {
                $c_start = $size - substr($range, 1);
            } else {
                $range = explode('-', $range);
                $c_start = $range[0];
                $c_end = isset($range[1]) && is_numeric($range[1]) ? $range[1] : $size;
            }
            $c_end = $c_end > $end ? $end : $c_end;
            if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {
                header('HTTP/1.1 416 Requested Range Not Satisfiable');
                header("Content-Range: bytes {$start}-{$end}/{$size}");
                exit;
            }
        }
        $start = $c_start;
        $end = $c_end;
        $length = $end - $start + 1;
        header('HTTP/1.1 206 Partial Content');
    }
    header("Content-Range: bytes {$start}-{$end}/{$size}");
    header("Content-Length: " . $length);
    //header("X-Sendfile: $file");exit;
    if (!($fp = @fopen($file, "rb"))) {
        exit;
    }
    fseek($fp, $start);
    while (!feof($fp)) {
        set_time_limit(0);
        print fread($fp, 1024 * 4);
        //输出文件
        flush();
        ob_flush();
    }
    fclose($fp);
}
예제 #5
0
 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);
 }
예제 #6
0
/**
 * 文件代理输出
 */
function file_proxy_out($file)
{
    if (!file_exists($file)) {
        show_json('file not exists', false);
    }
    $mime = get_file_mime(get_path_ext($file));
    header("Cache-Control:public");
    header("Content-Type:" . $mime);
    header("Content-Length: " . filesize($file));
    //输出总长
    $fp = fopen($file, "rb");
    set_time_limit(0);
    while (!feof($fp)) {
        print fread($fp, 1024 * 8);
        //输出文件
        flush();
        ob_flush();
    }
    fclose($fp);
    exit;
}
예제 #7
0
/**
 * 输出、文件下载
 * 默认以附件方式下载;$download为false时则为输出文件
 */
function file_put_out($file, $download = false)
{
    if (!is_file($file)) {
        print 'not a file!';
    }
    set_time_limit(0);
    //ob_clean();//清除之前所有输出缓冲
    if (!file_exists($file)) {
        print 'file not exists';
    }
    if (isset($_SERVER['HTTP_RANGE']) && $_SERVER['HTTP_RANGE'] != "" && preg_match("/^bytes=([0-9]+)-\$/i", $_SERVER['HTTP_RANGE'], $match) && $match[1] < $fsize) {
        $start = $match[1];
    } else {
        $start = 0;
    }
    $size = get_filesize($file);
    header("Cache-Control: public");
    header("X-Powered-By: HackExplorer.");
    if ($download) {
        header("Content-Type: application/octet-stream");
        $filename = $file;
        //解决在IE中下载时中文乱码问题
        if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) {
            $filename = str_replace('+', '%20', urlencode($filename));
        }
        header("Content-Disposition: attachment;filename=" . $filename);
    } else {
        $mime = get_file_mime(get_path_ext($file));
        header("Content-Type: " . $mime);
    }
    if ($start > 0) {
        header("HTTP/1.1 206 Partial Content");
        header("Content-Ranges: bytes" . $start . "-" . ($size - 1) . "/" . $size);
        header("Content-Length: " . ($size - $start));
    } else {
        header("Accept-Ranges: bytes");
        header("Content-Length: {$size}");
    }
    $fp = fopen($file, "rb");
    fseek($fp, $start);
    while (!feof($fp)) {
        print fread($fp, 1024 * 8);
        //输出文件
        flush();
        ob_flush();
    }
    fclose($fp);
}
예제 #8
0
/**
* Output, file download
 * Default attachment download; $ download is false when compared to the output file
*/
function file_put_out($file, $download = false)
{
    if (!is_file($file)) {
        show_json('not a file!');
    }
    set_time_limit(0);
    //ob_clean();//Clear until all output buffers
    if (!file_exists($file)) {
        show_json('file not exists', false);
    }
    if (isset($_SERVER['HTTP_RANGE']) && $_SERVER['HTTP_RANGE'] != "" && preg_match("/^bytes=([0-9]+)-\$/i", $_SERVER['HTTP_RANGE'], $match) && $match[1] < $fsize) {
        $start = $match[1];
    } else {
        $start = 0;
    }
    $size = get_filesize($file);
    $mime = get_file_mime(get_path_ext($file));
    if ($download || strstr($mime, 'application/')) {
        //Download or download application is set head
        $filename = get_path_this($file);
        //Download IE resolve when Chinese garbage problem
        if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT']) || preg_match('/Trident/', $_SERVER['HTTP_USER_AGENT'])) {
            if ($GLOBALS['config']['system_os'] != 'windows') {
                //win the host ie browser; Chinese file download urlencode problem
                $filename = str_replace('+', '%20', urlencode($filename));
            }
        }
        header("Content-Type: application/octet-stream");
        header("Content-Disposition: attachment;filename=" . $filename);
    }
    header("Cache-Control: public");
    header("X-Powered-By: kodExplorer.");
    header("Content-Type: " . $mime);
    if ($start > 0) {
        header("HTTP/1.1 206 Partial Content");
        header("Content-Ranges: bytes" . $start . "-" . ($size - 1) . "/" . $size);
        header("Content-Length: " . ($size - $start));
    } else {
        header("Accept-Ranges: bytes");
        header("Content-Length: {$size}");
    }
    $fp = fopen($file, "rb");
    fseek($fp, $start);
    while (!feof($fp)) {
        print fread($fp, 1024 * 8);
        //Output File
        flush();
        ob_flush();
    }
    fclose($fp);
}