示例#1
0
        protected void Btn_Submit_Click(object sender, EventArgs e)
        {
            string strcallback = "";

            if (callback != "")
            {
                strcallback = "parent." + callback + "();";
            }
            if (File_Upload.PostedFile.ContentLength == 0)
            {
                Lbl_Tip.Text = "请选择文件";
                return;
            }

            string errors = string.Empty;
            string Pic    = string.Empty;

            // 上传文件

            MW.Common.JUpload upload = new MW.Common.JUpload();
            upload.IsUsedFtp   = false;
            upload.FileSize    = filesize;
            upload.FileType    = filetype;
            upload.IsWaterMark = Utils.StrToBool(iswatermark.ToString(), false);

            if (File_Upload.PostedFile.ContentLength > 0)
            {
                string result = upload.SaveFile(File_Upload, tofilepath);

                if (result == "0")//文件格式不正确
                {
                    errors = "文件格式不正确 " + filetype;
                }
                else if (result == "1") //文件大小超过filesizeK
                {
                    errors = "文件大小超过 " + filesize + "K";
                }
                else if (result == "3") //文件大小超过filesizeK
                {
                    errors = "非法的文件 ";
                }
                else
                {
                    result = "/" + result.TrimStart('/');
                    Pic    = BasePage.GetWebPath + result;
                }
            }
            else
            {
                errors = "无数据提交";
            }
            if (errors != "")
            {
                Lbl_Tip.Text = errors;
            }
            else
            {
                Lbl_Tip.Text = "上传成功";
                if (ismultifile == 0)
                {
                    ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "<script>parent.document.all." + recievetxtname + ".value='" + Pic + "';" + strcallback + "</script>");
                }
                else
                {
                    //string result_html = "<a  target=\"_blank\" href=\"" + result + "\" style=\"font-size:14px;color:#3c3c3c\">" + result.Substring(result.LastIndexOf("/") + 1) + "</a><br /> ";
                    ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "<script>parent.document.all." + recievetxtname + ".value+='" + Pic + "\\n';" + strcallback + "</script>");
                }
            }
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            filesize   = LYRequest.GetInt("filesize", 1024);
            filetype   = LYRequest.GetString("filetype", "image");
            tofilepath = LYRequest.GetString("filepath", "/upLoads/");
            int type = LYRequest.GetInt("type", 0);

            if (!IsPostBack)
            {
                string errors = string.Empty;
                string Pic    = string.Empty;
                string file   = "";

                if (!chkLogin(type))
                {
                    errors = "未登录,请登陆后上传资源!";
                }
                else
                {// 上传文件
                    HttpFileCollection filecollection = HttpContext.Current.Request.Files;
                    HttpPostedFile     hpf            = filecollection.Get("filedata");
                    if (hpf == null)
                    {
                        hpf = filecollection.Get(0);
                    }
                    MW.Common.JUpload upload = new MW.Common.JUpload();
                    upload.IsUsedFtp   = false;
                    upload.FileSize    = filesize;
                    upload.FileType    = filetype;
                    upload.IsWaterMark = iswatermark;
                    try
                    {
                        if (hpf.ContentLength > 0)
                        {
                            string result = upload.SaveFile(hpf, tofilepath);

                            if (result == "0")//文件格式不正确
                            {
                                errors = "文件格式不正确 " + filetype;
                            }
                            else if (result == "1") //文件大小超过filesizeK
                            {
                                errors = "文件大小超过 " + filesize + "K";
                            }
                            else if (result == "3") //文件大小超过filesizeK
                            {
                                errors = "非法的文件 ";
                            }
                            else
                            {
                                result = "/" + result.TrimStart('/');
                                Pic    = BasePage.GetWebPath + result;
                                file   = hpf.FileName;
                            }
                        }
                        else
                        {
                            errors = "无数据提交";
                        }
                    }
                    catch (Exception)
                    {
                        errors = "没有上传文件";
                    }
                }

                HttpContext.Current.Response.Write("{'err':'" + jsonString(errors) + "','msg':'" + Pic + "','file':'" + jsonString(file) + "'}");
                HttpContext.Current.Response.End();
            }
        }