<?php
/*******************************************************************
 * 版权协议：2009-2019
 * 版权所有: PHP-北京金南曦网络技术有限公司旗下PHPWMS，PHP商城系统技术支持中心http://www.php188.net，并保留所有权利。 
 * PHP商城系统网址: http://www.php188.com
 * PHPWMS系统网址：http://www.phpwms.com
 * 销售电话：010-87875088
 * 销售电话：010-87875188 
*------------------------------------------------------------------
 * 这不是一个完全免费软件！您只能在不用于商业目的的前提下对程序代码进
 * 行修改和使用；不允许对程序代码以任何形式任何目的的再发布。
 *------------------------------------------------------------------
 * 文件名称：admin_file.php
 * 摘    要：后台文件管理器
 * 适用范围：PHPWMS 1.0
 * 版    本：1.0
 *------------------------------------------------------------------
 * Script Written By phpwms项目组
 * 最后更新： 2009-09-24 phpwms 由PHP金南曦网络技术有限公司整理发布
 *******************************************************************/
if(!defined('IN_SYS'))exit('access die');
if(!defined('PHP188_UPLOAD_MAIN_PATH'))define('PHP188_UPLOAD_MAIN_PATH',SYS_ROOT.'file/');
$task = $_GET['a'];
$f = $_GET['f'];
if(is_post()){
		if($_SERVER['REQUEST_METHOD']=='POST'){
			if($_FILES['upload_files_self']){
				if(!class_exists('Upload'))require SYS_ROOT.'/include/classes/upload.class.php';
				$up = new Upload();
				$up->upload_type = array('jpg','gif','png','swf','flv','fla','zip','rar','7z','tar','gz','doc','xls','pps','ppt');
				if(FALSE!=($do = $up->up('upload_files_self'))){
					$end = $do['end_file'];
					$exts = pathinfo($end);
					$exts = strtolower($exts['extension']);
					if($exts=='swf'){
						$type = 'flash';
					}elseif($exts=='flv' || $exts =='fla'){
						$type = 'flv';
					}elseif(in_array($exts,array('jpg','png','gif','bmp'))){
						$type = 'image';
					}else{
						$type = 'default';
					}
					insert_file($end);
					$c_msg = '';
					$root = get_cache(array('siteBase','sys_url'));
					$root = empty($root)?'../':$root;
					$name = array_pop(explode('/',$do['upload_part']));
					die('2|'.$root.$do['upload_part'].'+'.$do['format_size'].(!empty($c_msg)?'--<font color="red">'+$c_msg+'</font>':'').'+'.$type.'+'.$name);
				}else{
					$msg = $up->getMsg();
					$m = $msg['msg'];
					die('1|'.$m);
				}
			}else{
				exit('1|请选择要上传的文件');
			}
		}else{
			exit('access die');
		} 	
}

if(!empty($f)){
	$ext = strtolower(array_pop(explode('.',$f)));
	if(in_array($ext,array('jpg','gif','png'))){
		$is_pic = TRUE;
	}else{
		$is_pic = FALSE;
	}
}
$tpl->assign('is_pic',$is_pic);
$tpl->assign('files',$f);
$tpl->display('file.tpl');
/*
class file {
	protected $_upload_path = PHP188_UPLOAD_MAIN_PATH;//文件上传的主路径
	protected $_url_path = '';
	protected $_task = '';
	protected $_data = array();
	protected $_use_http = TRUE;
	protected $_type = 'default';
	protected $_lang = array();
	protected $_db = NULL;
	protected $_http_url = '';
	function __construct(){
		global $db,$_LANG;
		$this->_lang = $_LANG;
		//if(!$this->_logined)exit('access die,please login.');
		$this->_task = $_GET['a'];
		$url = get_cache(array('siteBase','sys_url'));
		$this->_http_url = $http_url = $this->_use_http?(empty($url)?'../':(substr($url,-1,1)=='/'?$url:$url.'/')):'';
		$this->_url_path = $http_url.$this->_url_path;
		$type= $_GET['type'];
		$type = empty($type)?'default':$type;
		$ty = array('flash','thumb','default','water','flv','fla','other');
		if(!in_array($type,$ty))$type = 'default';
		$this->_type = $type;
		$this->_db = $db;
		switch ($this->_task){
			case 'ajaxPic':
				$this->ajaxPicAction();
				break;
			case 'delete':
				$this->deleteAction();
				break;
			case 'view':
				$this->viewAction();
				break;
			case 'ajaxUpload':
				$this->ajaxUploadAction();			
				break;
			default:$this->defaultAction();
		}
	}

	private function _insert_file($file_name,$type = 'default'){
		return insert_file($file_name,$type);
	}
	function defaultAction(){
		$this->_task = 'default';
		$this->_ajax_url = 'admincp.php?action=file&a=ajaxPic&type='.$this->_type;
		require dirname(__FILE__).'/file/index.php';//加载模板文件
	}	

	function ajaxPicAction(){
		$this->_task = 'ajaxPic';
		$this->_listFile($this->_type);
		require dirname(__FILE__).'/file/index.php';//加载模板文件
	}
	function deleteAction(){
		$file_id = to_int($_GET['fid']);
		if(empty($file_id))exit('crack die');
		$select = $this->_db->fetch("SELECT * FROM ##__core_file WHERE `fid` = '$file_id';",TRUE);
		if($select['system']=='yes')exit('system file,can not delete.');
		if(!empty($select)){
			$this->_db->query("DELETE FROM ##__core_file WHERE `fid` = '$file_id';");
			@unlink(SYS_ROOT.$select['source_file']);
		}
		die('ok');
	}
	function viewAction(){
		$file = base64_decode($_GET['file']);
		if(empty($file))exit('empty view file');
		$http_url = $this->_use_http?'../':'';
		$site_url =  $http_url;
$str = '<div style="text-align:center;width:550px; height:450px;margin:0px auto;"><object height="400" width="500" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="'.$site_url.'/shopdata/editor/flvplayer.swf" name="movie" /><param value="high" name="quality" /><param value="true" name="allowFullScreen" /><param value="vcastr_file='.$file.'" name="FlashVars" /><embed height="400" width="500" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" flashvars="vcastr_file='.$file.'" allowfullscreen="true" src="'.$site_url.'../kindeditor/flvplayer.swf"></embed></object></div>';
echo $str;
exit();
	}
	function ajaxUploadAction(){
		if($_SERVER['REQUEST_METHOD']=='POST'){
			if($_FILES['upload_files_self']){
				//$site_cfg = get_cache();
				if(!class_exists('Upload'))require SYS_ROOT.'/include/classes/upload.class.php';
				$up = new Upload();
				$up->upload_type = array('jpg','gif','png','swf','flv','fla','zip','rar','7z','tar','gz','doc','xls','pps','ppt');
				if(FALSE!=($do = $up->up('upload_files_self'))){
					$end = $do['end_file'];
					$exts = pathinfo($end);
					$exts = strtolower($exts['extension']);
					if($exts=='swf'){$type = 'flash';}elseif($exts=='flv' || $exts =='fla'){$type = 'flv';}else{$type = 'default';}
					$this->_insert_file($end);
					$c_msg = '';
					die('2|'.$do['upload_part'].'+'.$do['format_size'].(!empty($c_msg)?'--<font color="red">'+$c_msg+'</font>':'').'+'.$type);
				}else{
					$msg = $up->getMsg();
					$m = $msg['msg'];
					die('1|'.$m);
				}
			}else{
				exit('1|请选择要上传的文件');
			}
		}else{
			exit('access die');
		} 	
	}
}
new file();*/
?>