多文件上传--3 (uploadImage.swf)

来源:互联网 发布:win7网络共享设置软件 编辑:程序博客网 时间:2024/05/22 08:26



源代码下载地址:

http://download.csdn.net/detail/vincent_void/4632113


本篇同二《多文件上传--2 uploadImage.swf》相比,只是增加了一个限制文件大小的功能。


页面引用代码如下所示:

    <div id="myContent">    </div>    <input type="hidden" id="IsUpload" value="" />    <script type="text/javascript">        window.onload = function () {            var params = {                uploadServerUrl: "upload.aspx", //上传响应页面(必须设置)                maxFileData: 1024 * 300,       //300KB                jsFunction: "upload",         //上传成功后回调JS                filter: "*.jpg;"        //上传文件类型限制            }            swfobject.embedSWF("ImageFlashUpload/flash/uploadImage.swf", "myContent", "600", "500", "10.0.0", "ImageFlashUpload/flash/expressInstall.swf", params);        }        function upload() {        }    </script>


upload.aspx 后台处理代码如下:

 protected void Page_Load(object sender, EventArgs e)    {        ImgSave();    }      /// <summary>    /// 批量上传    /// </summary>    public void ImgSave()    {        HttpFileCollection files = Request.Files;        if (files.Count == 0)        {            Response.Write("请勿直接访问本文件");            Response.End();        }                    string CorpImg = "~/images/" + DateTime.Now.ToString("yyyyMMdd") + "/";        string path = Server.MapPath(CorpImg); //"~/AdminUpload/Image/"        //如果目录不存在,则创建        if (!Directory.Exists(path)) Directory.CreateDirectory(path);               // 只取第 1 个文件        HttpPostedFile file = files[0];        if (file != null && file.ContentLength > 0)        {            // flash 会自动发送文件名到 Request.Form["fileName"]            #region 保存原始图片            string fileName =  DateTime.Now.ToString("yyyyMMddHHmmssfff") + Path.GetExtension(Request.Form["fileName"]);  //文件名            string savePath = path + "\\" + fileName;            file.SaveAs(savePath);            #endregion        }    }


多文件上传--2 (uploadImage.swf) 地址:http://blog.csdn.net/vincent_void/article/details/7902734


如有侵犯别人的著作权,请留言,我会关闭相关内容!

原创粉丝点击