<%@ Page Language="C#" %>

<%@ Import Namespace="System.IO" %>

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string dir = ""; if (User.Identity.IsAuthenticated) dir = "/p/a/"; else { if (ZK.ifLogin) dir = "/p/m/" + ZK.uid + "/"; else dir = "/p/m/0/"; }
            if (!Directory.Exists(Server.MapPath(dir))) Directory.CreateDirectory(Server.MapPath(dir));

            if (User.Identity.IsAuthenticated || ZK.ifVIP())
            {
                string strImages = WMfile.FileOpen(dir + "fck_swfupload.txt", "").Trim(); if (strImages.Contains("<p>")) strImages = strImages.Substring(strImages.IndexOf("<p>"));

                int iType = 0;

                string Pdir = "/App_Data/p/guest/" + DateTime.Now.ToString("yyyyMMdd") + "/"; if (ZK.ifLogin) Pdir = "/p/m/" + ZK.uid + "/"; if (User.Identity.IsAuthenticated) Pdir = "/p/a/" + DateTime.Now.ToString("yyyyMMdd") + "/";
                if (!Directory.Exists(Server.MapPath(Pdir))) Directory.CreateDirectory(Server.MapPath(Pdir));

                HttpPostedFile uploadFile = Request.Files["Filedata"];

                string FileName = ""; if (iType == 1) FileName = uploadFile.FileName; else FileName = DateTime.Now.ToString("yyyyMMddHHmmssfffffff") + "." + WMupload.GetPathExtension(uploadFile.FileName);
                FileName = FileName.Replace("..", ".");

                if (FileName.ToLower().Contains(".jpg") || FileName.ToLower().Contains(".jpeg") || FileName.ToLower().Contains(".gif") || FileName.ToLower().Contains(".png") || FileName.ToLower().Contains(".bmp"))
                {
                    uploadFile.SaveAs(Server.MapPath(Pdir) + FileName);
                    strImages += "<p><img class=\"zk_content_img\" alt=\"\" src=\"" + Pdir + FileName + "\" /></p><br />";
                    WMfile.FileCreate((WMarray.SplitArr(strImages, "</p>").Length-1).ToString() + strImages, dir + "fck_swfupload.txt");
                }
            }
        }
    }
</script>

