Пример #1
0
        public UploadResult Upload(UploadRequest req)
        {
            UploadResult rs = new UploadResult();

            rs.Msg  = "success";
            rs.Code = 0;
            // check
            string checkRs = CheckAviable(req);

            if (checkRs.Length > 0)
            {
                rs.Code = 1;
                rs.Msg  = checkRs;
                return(rs);
            }

            if (string.IsNullOrEmpty(req.FileName))
            {
                rs.Code = 2;
                rs.Msg  = "文件名称为空!";
                return(rs);
            }

            if (!CheckSignature())
            {
                rs.Code = 3;
                rs.Msg  = "授权失败!";
                return(rs);
            }

            FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\" + req.SaveVirtualPath + "\\" + req.FileName, FileMode.CreateNew, FileAccess.ReadWrite);

            try
            {
                fs.Write(req.FileBytes, 0, req.SaveVirtualPath.Length);
            }
            catch (Exception e)
            {
                rs.Code = 1;
                rs.Msg  = e.Message;
            }
            finally
            {
                fs.Close();
                fs.Dispose();
            }
            rs.ReturnFilePath = req.SaveVirtualPath + "\\" + req.FileName;
            return(rs);
        }
Пример #2
0
        public UploadResult Upload(UploadRequest req)
        {
            UploadResult rs = new UploadResult();
            rs.Msg = "success";
            rs.Code = 0;
            // check
            string checkRs = CheckAviable(req);
            if (checkRs.Length > 0)
            {
                rs.Code = 1;
                rs.Msg = checkRs;
                return rs;
            }

            if (string.IsNullOrEmpty(req.FileName))
            {
                rs.Code = 2;
                rs.Msg = "文件名称为空!";
                return rs;
            }

            if (!CheckSignature())
            {
                rs.Code = 3;
                rs.Msg = "授权失败!";
                return rs;
            }

            FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\" + req.SaveVirtualPath + "\\" + req.FileName, FileMode.CreateNew, FileAccess.ReadWrite);
            try
            {
                fs.Write(req.FileBytes, 0, req.SaveVirtualPath.Length);
            }
            catch (Exception e)
            {
                rs.Code = 1;
                rs.Msg = e.Message;
            }
            finally
            {
                fs.Close();
                fs.Dispose();
            }
            rs.ReturnFilePath = req.SaveVirtualPath + "\\" + req.FileName;
            return rs;
        }
Пример #3
0
 private string CheckAviable(UploadRequest req)
 {
     string fiel = req.SaveVirtualPath;
     if (ContainsIgnoreCase(fiel, ".asp")
         || ContainsIgnoreCase(fiel, ".aspx")
         || ContainsIgnoreCase(fiel, ".cs")
         || ContainsIgnoreCase(fiel, ".js")
         || ContainsIgnoreCase(fiel, ".php")
         || ContainsIgnoreCase(fiel, ".jsp")
         || ContainsIgnoreCase(fiel, ".java")
         || ContainsIgnoreCase(fiel, ".cgi")
         || ContainsIgnoreCase(fiel, ".ashx")
         || ContainsIgnoreCase(fiel, ".asmx")
         )
     {
         return "文件格式不被允许或不符合标准格式";
     }
     return string.Empty;
 }
Пример #4
0
        private string CheckAviable(UploadRequest req)
        {
            string fiel = req.SaveVirtualPath;

            if (ContainsIgnoreCase(fiel, ".asp") ||
                ContainsIgnoreCase(fiel, ".aspx") ||
                ContainsIgnoreCase(fiel, ".cs") ||
                ContainsIgnoreCase(fiel, ".js") ||
                ContainsIgnoreCase(fiel, ".php") ||
                ContainsIgnoreCase(fiel, ".jsp") ||
                ContainsIgnoreCase(fiel, ".java") ||
                ContainsIgnoreCase(fiel, ".cgi") ||
                ContainsIgnoreCase(fiel, ".ashx") ||
                ContainsIgnoreCase(fiel, ".asmx")
                )
            {
                return("文件格式不被允许或不符合标准格式");
            }
            return(string.Empty);
        }