using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using TopWinCMS.BLL;
namespace TopWinCMS.WebUI.Admin.Explorer
{
    public partial class FilesUpload : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {


                RightsCheck.CheckWorkPower("P_2");
            }
        }

        private void uploadfile()
        {
            string finfo = "";
            for (int i = 0; i <= Request.Files.Count - 1; i++)
            {
                if (UpFileHepler.Check(Request.Files[i].FileName) == false)
                {
                    continue;
                }

                HttpPostedFile PostedFile = Request.Files[i];
                if (PostedFile.ContentLength > 0)
                {
                    string _int;
                    if (PostedFile.ContentLength / 1024 > 1024)
                    {
                        _int = PostedFile.ContentLength / 1024 / 1024 + " MB";
                    }
                    else if (PostedFile.ContentLength / 1024 > 1024)
                    {
                        _int = PostedFile.ContentLength / 1024 + " KB";
                    }
                    else
                    {
                        _int = PostedFile.ContentLength + "字节";
                    }
                    finfo = finfo + "文件名称:" + PostedFile.FileName + "<br>";
                    finfo = finfo + "文件大小:" + _int + "<br>";
                    finfo = finfo + "文件类型:" + PostedFile.ContentType + "<br>";
                    string[] filesplit = PostedFile.FileName.Split('\\');
                    string Filename = filesplit[filesplit.Length - 1];
                    if (Request["dir"] == null)
                    {
                        string path = Server.MapPath(Config.UP);
                        PostedFile.SaveAs(path + Filename);
                        Response.Redirect("Serverlist.aspx?dir=" + path);
                    }
                    else
                    {
                        PostedFile.SaveAs(Request["dir"] + "\\" + Filename);
                        Response.Redirect("Serverlist.aspx?dir=" + Request["dir"]);
                    }
                }
            }
            fileinfo.InnerHtml = finfo;
        }

        protected void Upload_Click(object sender, System.EventArgs e)
        {
            uploadfile();
        }

        protected void Button1_Click(object sender, System.EventArgs e)
        {
            show1.Text = show1.Text + "<Input type='file' id=1 runat='Server' NAME=1>";
        }
    }
}
