Edit D:\AVAWeike\AVAWeike\AVA.ResourcesPlatform.WebUI\JS\zh-CN\XhEditor\Upload.aspx
??<%@ Page Language="C#" AutoEventWireup="true" CodePage="65001" %> <%@ Import Namespace="System" %> <%@ Import Namespace="System.Collections" %> <%@ Import Namespace="System.Configuration" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Web" %> <%@ Import Namespace="System.Web.Security" %> <%@ Import Namespace="System.Web.UI" %> <%@ Import Namespace="System.Web.UI.HtmlControls" %> <%@ Import Namespace="System.Web.UI.WebControls" %> <%@ Import Namespace="System.Web.UI.WebControls.WebParts" %> <script runat="server"> /* * upload demo for c# .net 2.0 * * @requires xhEditor * @author Jediwolf<jediwolf@gmail.com> * @licence LGPL(http://www.opensource.org/licenses/lgpl-license.php) * * @Version: 0.1.3 (build 100504) * * ??1?????????????????????????????????????????????????? * ??2????????TML5????????OST????????yte????????? * */ protected void Page_Load(object sender, EventArgs e) { Response.Charset = "UTF-8"; // ???????????? string inputname = "filedata";//??????name string attachdir = SettingGroup.XhEditorUploadPath.Trim('\\'); // ?????????????????????/ if (attachdir.LastIndexOf("/") == attachdir.Length - 1) { //?????? / ???????? attachdir = attachdir.Substring(0, attachdir.Length - 1); } int dirtype = 1; // 1:????????? 2:????????? 3:??????????? ??????????? int maxattachsize = 2097152 * 10; // ????????????????2M string upext = "txt,rar,zip,7z,jpg,jpeg,gif,png,swf,wmv,avi,wma,mp3,mid"; // ???????? int msgtype = 2; //???????????????1??????url??2??????????? string immediate = Request.QueryString["immediate"];//?????????????????? byte[] file; // ????????yte?????? string localname = ""; string disposition = Request.ServerVariables["HTTP_CONTENT_DISPOSITION"]; string err = ""; string msg = "''"; if (disposition != null) { // HTML5??? file = Request.BinaryRead(Request.TotalBytes); localname = Regex.Match(disposition, "filename=\"(.+?)\"").Groups[1].Value;// ??????????? } else { HttpFileCollection filecollection = Request.Files; HttpPostedFile postedfile = filecollection.Get(inputname); // ??????????? localname = postedfile.FileName; // ?????yte???. file = new Byte[postedfile.ContentLength]; // ?????yte??? System.IO.Stream stream = postedfile.InputStream; stream.Read(file, 0, postedfile.ContentLength); stream.Close(); filecollection = null; } if (file.Length == 0) err = "????????"; else { if (file.Length > maxattachsize) err = "?????????" + AVA.ResourcesPlatform.Config.Helper.FormatSize(maxattachsize) + "?????????????????" + AVA.ResourcesPlatform.Config.Helper.FormatSize(file.Length); else { string attach_dir, attach_subdir, filename, extension, target; // ????????????? extension = GetFileExt(localname); if (("," + upext + ",").IndexOf("," + extension + ",") < 0) err = "?????????????????" + upext; else { switch (dirtype) { case 2: attach_subdir = "month_" + DateTime.Now.ToString("yyMM"); break; case 3: attach_subdir = "ext_" + extension; break; default: attach_subdir = "day_" + DateTime.Now.ToString("yyMMdd"); break; } attach_dir = attachdir + "/" + attach_subdir + "/"; // ??????????? Random random = new Random(DateTime.Now.Millisecond); filename = DateTime.Now.ToString("yyyyMMddhhmmss") + random.Next(10000) + "." + extension; target = attach_dir + filename; try { CreateFolder(Server.MapPath(attach_dir)); System.IO.FileStream fs = new System.IO.FileStream(Server.MapPath(target), System.IO.FileMode.Create, System.IO.FileAccess.Write); fs.Write(file, 0, file.Length); fs.Flush(); fs.Close(); } catch (Exception ex) { err = ex.Message.ToString(); } // ????????? if (immediate == "1") target = "!" + target; target = jsonString(target); if (msgtype == 1) msg = "'" + target + "'"; else msg = "{'url':'" + target + "','localname':'" + jsonString(localname) + "','id':'1'}"; } } } file = null; Response.Write("{'err':'" + jsonString(err) + "','msg':" + msg + "}"); } string jsonString(string str) { str = str.Replace("\\", "\\\\"); str = str.Replace("/", "\\/"); str = str.Replace("'", "\\'"); return str; } string GetFileExt(string FullPath) { if (FullPath != "") return FullPath.Substring(FullPath.LastIndexOf('.') + 1).ToLower(); else return ""; } void CreateFolder(string FolderPath) { if (!System.IO.Directory.Exists(FolderPath)) System.IO.Directory.CreateDirectory(FolderPath); } </script>
Ms-Dos/Windows
Unix
Write backup
jsp File Browser version 1.2 by
www.vonloesch.de