예제 #1
0
        //合成文本长度必须小于1024字节,如果本文长度较长,可以采用多次请求的方式。切忌不可文本长度超过限制。
        public static string GetSoundFromBiadu(string text, string md5)
        {
            text = text.Trim();
            //string token = "24.7a59ff42a21e6a68093775145c531e78.2592000.1452835747.282335-7499115";
            M_API_BaiduSound apiMod = new M_API_BaiduSound();

            apiMod.tok  = GetToken();
            apiMod.tex  = text;
            apiMod.cuid = "zoomla_api_tosound";
            string          data       = apiMod.ToParamStr();
            string          url        = "http://tsn.baidu.com/text2audio";
            HttpWebResponse rep        = ProcessRequest(url, data);
            Stream          dataStream = rep.GetResponseStream();

            byte[] file  = IOHelper.StreamToBytes(dataStream);
            string fpath = SafeSC.SaveFile(vpath, md5 + ".mp3", file);

            dataStream.Close();
            rep.Close();
            return(fpath);
        }
예제 #2
0
        protected void SFile_Btn_Click(object sender, EventArgs e)
        {
            M_UserInfo mu      = buser.GetLogin();
            ImgHelper  imghelp = new ImgHelper();
            string     fpath   = B_Design_SiteInfo.GetSiteUpDir(mu.SiteID);

            if (!SafeSC.IsImage(SFile_UP.FileName))
            {
                function.WriteErrMsg("上传的图片后缀名不允许");
            }
            if (Path.GetExtension(SFile_UP.FileName).Equals(".gif"))
            {
                fpath = SafeSC.SaveFile(fpath, SFile_UP, function.GetFileName() + Path.GetExtension(SFile_UP.FileName));
            }
            else
            {
                fpath += function.GetFileName() + Path.GetExtension(SFile_UP.FileName);
                imghelp.CompressImg(SFile_UP.PostedFile, 1024, fpath);
            }
            function.Script(this, "setTimeout(function () { updateiurl('" + fpath + "');},50);");
        }
예제 #3
0
        //物理路径,上传控件,如无文件时默认文件虚拟路径
        private void SaveFile(string path, string file, string defVPath)
        {
            path = path.Replace(@"\\", @"\");
            if (System.IO.File.Exists(path))
            {
                System.IO.File.Delete(path);
            }
            string filepath = function.VToP(file);

            if (!string.IsNullOrEmpty(file) && System.IO.File.Exists(filepath))
            {
                byte[] data = System.IO.File.ReadAllBytes(filepath);
                SafeSC.SaveFile(function.PToV(path), "", data);
            }
            else
            {
                if (!string.IsNullOrEmpty(defVPath))
                {
                    System.IO.File.Copy(Server.MapPath(defVPath), path);
                }
            }
        }
예제 #4
0
        protected void FileUp_Btn_Click(object sender, EventArgs e)
        {
            M_UserInfo mu = buser.GetLogin();

            if (!FileUp_File.HasFile)
            {
                function.Script(this, "请指定一个上传文件"); return;
            }
            string ext = Path.GetExtension(FileUp_File.FileName).ToLower();
            //if (ext.Equals(".html") || ext.Equals(".html") || ext.Equals(".shtml")) { function.Script(this, "不允许上传html文件"); return; }

            string fname    = DataSecurity.MakeFileRndName() + ext;
            string dirPath  = SiteConfig.SiteOption.UploadDir + "UserUpload/" + mu.UserName + mu.UserID + "/";
            string savePath = SafeSC.SaveFile(dirPath, FileUp_File, fname);

            if (WaterModuleConfig.WaterConfig.IsUsed && SafeSC.IsImage(FileUp_File.FileName))
            {
                savePath = ImgHelper.AddWater(savePath);
            }
            function.Script(this, "ZLIfrField.UploadPic(\"" + savePath + "\",\"" + FieldName + "\");");
            LblMsg_L.Text = "文件上传成功";
        }
예제 #5
0
        public void BatUpload()
        {
            string Case = Request["case"] ?? "";

            if (!string.IsNullOrEmpty(Case))
            {
                string myCase = Server.UrlDecode(Case);
                SafeSC.CreateDir("~/uploadFiles/DocTemp/", myCase);
                string path = Server.MapPath("~/uploadFiles/DocTemp/" + myCase + "/");
                //目录建好了,然后我们开始存文档
                Response.Clear();
                //ID为文档的主键,如果ID不为空,则更新数据,否则新建一条记录
                string ID = Request.Params["ID"];
                string DocTitle, content;
                DocTitle = "test";
                if (!string.IsNullOrEmpty(ID))
                {
                    DocTitle = Server.UrlDecode(Request.Params["DocTitle"]);
                }
                DocTitle = Server.UrlDecode(Request.Params["DocTitle"]);
                content  = Server.UrlDecode(Request.Params["content"]);
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase upPhoto = Request.Files[0];
                    int    upPhotoLength       = upPhoto.ContentLength;
                    byte[] PhotoArray          = new Byte[upPhotoLength];
                    Stream PhotoStream         = upPhoto.InputStream;
                    PhotoStream.Read(PhotoArray, 0, upPhotoLength); //这些编码是把文件转换成二进制的文件
                    if (DocTitle.ToLower().Contains(".cshtml") || DocTitle.ToLower().Contains(".aspx") || DocTitle.ToLower().Contains(".exe"))
                    {
                        return;
                    }
                    SafeSC.SaveFile(path, DocTitle, PhotoArray);
                }
                Response.ContentType = "text/plain";
                Response.Write("Complete"); Response.Flush(); Response.End(); return;
            }
        }
예제 #6
0
        //根据csv或xlsx,将数据导入数据库
        public void ContentManage_Import()
        {
            HttpPostedFileBase file = Request.Files["fileImp"];

            if (file == null)
            {
                function.WriteErrMsg("没有上传数据文件"); return;
            }
            string exName = Path.GetExtension(file.FileName).ToLower();

            if (!exName.Equals(".csv") && !exName.Equals(".xls") && !exName.Equals(".xlsx"))//判断扩展名
            {
                function.WriteErrMsg("上传的文件不是符合扩展名csv,请重新选择!"); return;
            }
            string vpath = SafeSC.SaveFile(ZLHelper.GetUploadDir_System("Content", "Import", "yyyyMMdd"), function.GetRandomString(6) + exName, IOHelper.StreamToBytes(file.InputStream));
            //导入文件到数据集对象
            DataTable dt = null;

            if (exName.Equals(".csv"))
            {
                OfficeHelper office = new OfficeHelper();
                dt = office.OpenCSV(vpath);
            }
            else
            {
                SqlBase excel = SqlBase.CreateHelper("excel");
                excel.ConnectionString = vpath;
                dt = excel.ExecuteTable(new SqlModel()
                {
                    tbName = excel.Table_List().Rows[0]["name"].ToString()
                });
            }
            SafeSC.DelFile(vpath);
            DataSet newDs = Import_CreateTable(dt);

            Import_SaveDB(newDs);//保存到数据库
        }
예제 #7
0
    /// <summary>
    /// 存储文件,返回虚拟路径,注意IE下其是全路径,Chrome下仅文件名
    /// </summary>
    public string SaveFile(HttpPostedFile file, SaveType type, string value = "")
    {
        string result = "";

        if (file.ContentLength < 1)
        {
            return("");
        }
        string path = "", filename = "";

        switch (type)
        {
        case SaveType.Sign:    //组名||用户名
            path = OADir + @"\Sign\" + value + @"\";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            filename = GetFileName(path, file.FileName);
            SafeSC.SaveFile(path + filename, file);
            result = path + filename;
            break;

        case SaveType.Mail:
            path = OADir + @"\Mail\" + value + @"\";    //用户名
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            filename = GetFileName(path, file.FileName);
            SafeSC.SaveFile(path + filename, file);
            result = path + filename;
            break;
        }
        return(function.PToV(result));
    }
        //保存上传的文件
        public string SaveFile()
        {
            oaVPath += DateTime.Now.ToString("yyyyMMddHHmmss") + "/";
            string oaPPath = Server.MapPath(oaVPath);
            string result  = "";

            if (Request.Files.Count > 0)
            {
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    if (Request.Files[i].ContentLength < 1)
                    {
                        continue;                                    //为空则不处理
                    }
                    if (!Directory.Exists(oaPPath))
                    {
                        Directory.CreateDirectory(oaPPath);
                    }
                    SafeSC.SaveFile(oaPPath + Path.GetFileName(Request.Files[i].FileName), Request.Files[i]);
                    result += oaVPath + Path.GetFileName(Request.Files[i].FileName) + ",";
                }
            }
            return(result);
        }
 }                                                                                                //仅传文件名
                                                                                                  //稍后改为直接存入字段中
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Request.Files.Count > 0)
     {
         HttpPostedFile file = Request.Files[0];
         if (AppID > 0)
         {
             M_OA_Document oaMod = oaBll.SelReturnModel(AppID);
             M_UserInfo    mu    = buser.SelReturnModel(oaMod.UserID);
             SafeSC.SaveFile(oacom.GetMyDir(mu), file, FName);
         }
         else//第一次创建
         {
             M_UserInfo mu = buser.GetLogin();
             SafeSC.SaveFile(oacom.GetMyDir(mu), file, FName);
         }
         Response.Write("true");
     }
     else
     {
         Response.Write("No File Upload!");
     }
     Response.End();
 }
예제 #10
0
    public override void Process()
    {
        byte[] uploadFileBytes = null;
        string uploadFileName  = null;

        if (UploadConfig.Base64)
        {
            uploadFileName  = UploadConfig.Base64Filename;
            uploadFileBytes = Convert.FromBase64String(Request[UploadConfig.UploadFieldName]);
        }
        else
        {
            var file = Request.Files[UploadConfig.UploadFieldName];
            uploadFileName = file.FileName;

            if (!CheckFileType(uploadFileName))
            {
                Result.State = UploadState.TypeNotAllow;
                WriteResult();
                return;
            }
            if (!CheckFileSize(file.ContentLength))
            {
                Result.State = UploadState.SizeLimitExceed;
                WriteResult();
                return;
            }

            uploadFileBytes = new byte[file.ContentLength];
            try
            {
                file.InputStream.Read(uploadFileBytes, 0, file.ContentLength);
            }
            catch (Exception)
            {
                Result.State = UploadState.NetworkError;
                WriteResult();
            }
        }

        Result.OriginFileName = uploadFileName;

        var    savePath  = PathFormatter.Format(uploadFileName, UploadConfig.PathFormat);
        var    localPath = Server.MapPath(savePath);
        string vdir      = function.PToV(Path.GetDirectoryName(localPath)) + "/";
        string fname     = Path.GetFileName(localPath);

        if (!Directory.Exists(Path.GetDirectoryName(localPath)))
        {
            Directory.CreateDirectory(Path.GetDirectoryName(localPath));
        }
        try
        {
            if (UploadConfig.IsBar)//压缩图片,水印,如访问量大,应将其生成临时表
            {
                var             file  = Request.Files[UploadConfig.UploadFieldName];
                M_GuestBookCate model = GetBarModel(UploadConfig);
                if (model == null)
                {
                    throw new Exception("贴吧图片上传出错,model的值为空");
                }
                if (model.ZipImgSize > 0 && file.ContentLength > (model.ZipImgSize * 1024))
                {
                    imghelper.CompressImg(file, model.ZipImgSize, savePath);//需改为读取版面配置
                }
                else
                {
                    ZLLog.L("here2");
                    //string fname = Path.GetFileName(localPath);
                    savePath = SafeSC.SaveFile(vdir, fname, uploadFileBytes);
                    //File.WriteAllBytes(localPath, uploadFileBytes);
                }
                savePath = ImgHelper.AddWater(savePath);
            }
            else
            {
                savePath = SafeSC.SaveFile(vdir, fname, uploadFileBytes);
                savePath = ImgHelper.AddWater(savePath);
            }
            Result.Url   = savePath;
            Result.State = UploadState.Success;
        }
        catch (Exception e)
        {
            Result.State        = UploadState.FileAccessError;
            Result.ErrorMessage = e.Message;
        }
        finally
        {
            WriteResult();
        }
    }
예제 #11
0
        public override void Process()
        {
            byte[] uploadFileBytes = null;
            string uploadFileName  = null;

            if (UploadConfig.Base64)
            {
                uploadFileName  = UploadConfig.Base64Filename;
                uploadFileBytes = Convert.FromBase64String(Request.GetParam(UploadConfig.UploadFieldName));
            }
            else
            {
                var file = Request.Form.Files[UploadConfig.UploadFieldName];
                uploadFileName = file.FileName;
                if (!CheckFileType(uploadFileName))
                {
                    Result.State = UploadState.TypeNotAllow;
                    WriteResult();
                    return;
                }
                if (!CheckFileSize((int)file.Length))
                {
                    Result.State = UploadState.SizeLimitExceed;
                    WriteResult();
                    return;
                }

                uploadFileBytes = new byte[(int)file.Length];
                try
                {
                    file.OpenReadStream().Read(uploadFileBytes, 0, (int)file.Length);
                }
                catch (Exception)
                {
                    Result.State = UploadState.NetworkError;
                    WriteResult();
                }
            }

            Result.OriginFileName = uploadFileName;

            var    savePath  = PathFormatter.Format(uploadFileName, UploadConfig.PathFormat);
            var    localPath = function.VToP(savePath);
            string vdir      = function.PToV(Path.GetDirectoryName(localPath)) + "/";
            string fname     = Path.GetFileName(localPath);

            if (!Directory.Exists(Path.GetDirectoryName(localPath)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(localPath));
            }
            try
            {
                if (UploadConfig.IsBar)//压缩图片,水印,如访问量大,应将其生成临时表
                {
                    var file = Request.Form.Files[UploadConfig.UploadFieldName];
                    //M_GuestBookCate model = GetBarModel(UploadConfig);
                    //if (model == null) { throw new Exception("贴吧图片上传出错,model的值为空"); }
                    //if (model.ZipImgSize > 0 && file.ContentLength > (model.ZipImgSize * 1024))
                    //{
                    //    imghelper.CompressImg(file, model.ZipImgSize, savePath);//需改为读取版面配置
                    //}
                    //else
                    //{
                    //    //string fname = Path.GetFileName(localPath);
                    savePath = SafeSC.SaveFile(vdir, fname, uploadFileBytes);
                    //    //File.WriteAllBytes(localPath, uploadFileBytes);
                    //}
                    //if (SafeSC.IsImage(savePath))
                    //{
                    //    savePath = ImgHelper.AddWater(savePath);
                    //}
                }
                else
                {
                    savePath = SafeSC.SaveFile(vdir, fname, uploadFileBytes);
                    //M_UserInfo mu = new B_User(HttpContext.Current).GetLogin();
                    //if (WaterModuleConfig.WaterConfig.EnableUserWater && !mu.IsNull)
                    //{
                    //    System.Drawing.Image img = WaterImages.DrawFont(ImgHelper.ReadImgToMS(savePath), mu.UserName + " " + DateTime.Now.ToString("yyyy/MM/dd"), 9);
                    //    ImgHelper.SaveImage(savePath, img);
                    //}
                    //if (SafeSC.IsImage(savePath))
                    //{
                    //    if (WaterModuleConfig.WaterConfig.IsUsed)
                    //    {
                    //        savePath = ImgHelper.AddWater(savePath);
                    //    }
                    //}
                }
                Result.Url   = savePath;
                Result.State = UploadState.Success;
            }
            catch (Exception e)
            {
                Result.State        = UploadState.FileAccessError;
                Result.ErrorMessage = e.Message;
            }
            finally
            {
                WriteResult();
            }
        }
        public string SaveFile()
        {
            //if (string.IsNullOrEmpty(FVPath_T.Text) && !IsNull) { function.WriteErrMsg("请选择上传文件!"); }
            //如未指定上传文件,则返回FVPath中的值,便于清空与拷贝地址进入
            if (!FileUp_File.HasFile)
            {
                return(FVPath);
            }
            string filename = filename = FileUp_File.FileName;

            if (!IsRelName)
            {
                filename = DateTime.Now.ToString("yyyyMMddHHmmss") + function.GetRandomString(4) + Path.GetExtension(FileUp_File.FileName);
            }
            switch (FType)
            {
            case FileType.Img:
            {
                if (!SafeSC.IsImage(FileUp_File.FileName))
                {
                    function.WriteErrMsg(Path.GetExtension(FileUp_File.FileName) + "不是有效的图片格式!");
                }
                ImgHelper imghelp = new ImgHelper();
                //if (IsCompress)//压缩与最大比只能有一个生效
                //{
                //    imghelp.CompressImg(FileUp_File.PostedFile, 1000, vpath);
                //}
                bool hasSave = false;
                if (MaxWidth > 0 || MaxHeight > 0)
                {
                    System.Drawing.Image img = System.Drawing.Image.FromStream(FileUp_File.PostedFile.InputStream);
                    img     = imghelp.ZoomImg(img, MaxHeight, MaxWidth);
                    FileUrl = ImgHelper.SaveImage(SaveUrl + filename, img);
                    hasSave = true;
                }
                if (!hasSave)
                {
                    FileUrl = SafeSC.SaveFile(SaveUrl, FileUp_File, filename);
                }
            }
            break;

            case FileType.Office:
            {
                if (!exname.Contains(Path.GetExtension(FileUp_File.FileName)))
                {
                    function.WriteErrMsg("必须上传doc|docx|xls|xlsx格式的文件!");
                }
                FileUrl = SafeSC.SaveFile(SaveUrl, FileUp_File, filename);
            }
            break;

            default:
            {
                FileUrl = SafeSC.SaveFile(SaveUrl, FileUp_File, filename);
            }
            break;
            }
            //FileUrl = SaveUrl + filename;
            //if (!Directory.Exists(function.VToP(SaveUrl))) { SafeSC.CreateDir(SaveUrl); }
            //if (!FileUp_File.SaveAs(FileUrl)) { function.WriteErrMsg(FileUp_File.ErrorMsg); }
            return(FileUrl);
        }
예제 #13
0
        }                                                                                                                     //仅传文件名
        public void ProcessRequest(HttpContext context)
        {
            HttpRequest  Request  = context.Request;
            HttpResponse Response = context.Response;
            string       action   = Request["action"];

            switch (action)
            {
            case "getword":    //返回Word二进制文件
            {
                Response.Clear();
                Response.ContentType = "Application/msword";
                string fname = HttpUtility.UrlDecode(Request["fname"]);
                int    appid = DataConverter.CLng(Request["appid"]);
                string vpath = "";
                if (appid > 0)
                {
                    M_OA_Document oaMod = oaBll.SelReturnModel(appid);
                    M_UserInfo    mu    = buser.SelReturnModel(oaMod.UserID);
                    vpath = oacom.GetMyDir(mu) + HttpUtility.UrlDecode(oaMod.PrivateAttach);
                }
                else
                {
                    M_UserInfo mu = buser.GetLogin();
                    vpath = oacom.GetMyDir(mu) + fname;
                }
                Response.BinaryWrite(SafeSC.ReadFileByte(vpath));           //读取二进制的文件
                Response.Flush(); Response.End();
            }
            break;

            case "saveword":
            {
                if (Request.Files.Count > 0)
                {
                    HttpPostedFile file = Request.Files[0];
                    if (AppID > 0)
                    {
                        M_OA_Document oaMod = oaBll.SelReturnModel(AppID);
                        M_UserInfo    mu    = buser.SelReturnModel(oaMod.UserID);
                        SafeSC.SaveFile(oacom.GetMyDir(mu), file, FName);
                    }
                    else        //第一次创建
                    {
                        HttpContext curReq = HttpContext.Current;
                        if (curReq.Request.Cookies["UserState"] != null)
                        {
                            string loginName = curReq.Request.Cookies["UserState"]["LoginName"], password = curReq.Request.Cookies["UserState"]["Password"];
                            ZLLog.L("SaveWord:" + loginName + ":" + password);
                        }
                        else
                        {
                            ZLLog.L("SaveWord:empty");
                        }
                        M_UserInfo mu = buser.GetLogin();
                        SafeSC.SaveFile(oacom.GetMyDir(mu), file, FName);
                    }
                    Response.Write("true");
                }
                else
                {
                    Response.Write("No File Upload!");
                }
            }
            break;
            }
        }
예제 #14
0
        protected void uploadok_Click(object sender, EventArgs e)
        {
            string upclass, newtimename, filenames, filext, filesname, indexname, timename, tempfilename, showfilename;

            upclass = Server.HtmlEncode(Request.QueryString["menu"]);

            fileupload.Visible = false;
            uploadok.Text      = "正在上传...请稍候!";
            uploadok.Enabled   = false;

            Int32 filesize;

            filenames = fileupload.FileName;
            filext    = fileupload.PostedFile.ContentType;
            filesize  = fileupload.PostedFile.ContentLength;

            if (filenames.Length > 0)
            {
                if (filenames.IndexOf(".") > 0)
                {
                    filesname = filenames.Substring(filenames.LastIndexOf(".")).ToLower();
                    Random indexcc = new Random();
                    indexname = Convert.ToString(indexcc.Next(9999));
                    timename  = Convert.ToString(DateTime.Now);
                    string dirname;
                    dirname = Convert.ToString(DateTime.Now.Date.ToShortDateString());

                    if (!Directory.Exists(Server.MapPath("../" + SiteConfig.SiteOption.UploadDir + "/" + dirname)))
                    {
                        Directory.CreateDirectory(Server.MapPath("../" + SiteConfig.SiteOption.UploadDir + "/" + dirname));
                    }
                    newtimename  = Convert.ToString(DateTime.Now.Year) + Convert.ToString(DateTime.Now.Month) + Convert.ToString(DateTime.Now.Day) + Convert.ToString(DateTime.Now.Hour) + Convert.ToString(DateTime.Now.Minute) + Convert.ToString(DateTime.Now.Second) + Convert.ToString(DateTime.Now.Millisecond);
                    tempfilename = "../" + SiteConfig.SiteOption.UploadDir + "/" + dirname + "/" + newtimename + indexname + filesname;
                    showfilename = dirname + "/" + newtimename + indexname + filesname;

                    if (fileupload.HasFile)
                    {
                        if (!chackext(filesname))
                        {
                            uploadok.Visible = false;
                            Response.Write("错误的文件类型!系统不支持" + filesname + "格式 <a href=FileUpload.aspx?menu=" + upclass + ">重新上传</a>");
                        }
                        else
                        {
                            try
                            {
                                SafeSC.SaveFile(tempfilename, fileupload, newtimename + indexname + filesname);
                                uploadok.Visible = false;
                                Response.Write("<script>parent.form1." + upclass + ".value='" + showfilename + "';document.oncontextmenu = new Function('return false');</script>");
                                Response.Write("上传成功! 文件大小:" + filesize + "字节 <a href=FileUpload.aspx?menu=" + upclass + ">重新上传</a>");
                            }
                            catch (Exception err)
                            {
                                uploadok.Visible = false;
                                Response.Write("上传失败!错误原因:" + err.Message + " <a href=FileUpload.aspx?menu=" + upclass + ">重新上传</a>");
                            }
                        }
                    }
                    else
                    {
                        uploadok.Visible = false;
                        Response.Write("请选择非空图片文件再上传! <a href=FileUpload.aspx?menu=" + upclass + ">重新上传</a>");
                    }
                }
                else
                {
                    uploadok.Visible = false;
                    Response.Write("系统不支持扩展名为空格式的文件! <a href=FileUpload.aspx?menu=" + upclass + ">重新上传</a>");
                }
            }
            else
            {
                uploadok.Visible = false;
                Response.Write("请选择图片文件再上传! <a href=FileUpload.aspx?menu=" + upclass + ">重新上传</a>");
            }
        }