• 上传图片


    namespace JngsWeb.Web.Interface
    {
    public partial class fileupload : System.Web.UI.Page
    {
    MultipartDataInfo mdi;
    protected void Page_Load(object sender, EventArgs e)
    {

    SendResponse(Response, Dopost());
    }

    private void SendResponse(HttpResponse response, string data)
    {
    response.Clear();
    response.Cache.SetCacheability(HttpCacheability.NoCache);
    response.Buffer = true;
    response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
    response.Cache.SetExpires(DateTime.Now.AddDays(-1));
    response.Expires = 0;
    response.CacheControl = "no-cache";
    response.Cache.SetNoStore();
    response.Write(data);
    response.Flush();
    response.End();
    }

    private string Dopost()
    {
    JsonData jd = new JsonData();
    JsonBase.AddJsonArray("result", ref jd);
    try
    {
    mdi = new MultipartDataInfo();

    mdi.CollectFormDatas();
    string img = "";
    string FileRealName = "";
    string FileServerName = "";
    string path;
    path = "../filehtml/";
    mdi.RootPath = path;

    if (mdi.FileCount > 0)
    {

    mdi.Save();
    foreach (MyFileInfo mfi in mdi.FileCollections)
    {
    try
    {
    FileServerName = mfi.FileName;
    FileRealName = mfi.SFileName;

    Dictionary<string, string> dict = new Dictionary<string, string>();
    string parent_id = mdi.FormCollections["parent_id"];

    string img_type = mdi.FormCollections["img_type"];
    string img_title = mdi.FormCollections["img_title"];
    string normal_img = "filehtml/" + FileServerName;

    if (string.IsNullOrEmpty(img))
    {
    img = normal_img;
    }
    else {
    img = "" + img + "," + normal_img + "";
    }
    string timg = Server.MapPath(path + FileServerName);

    if (img_type == "tousu_123")
    {
    string sql = "select * from tousu_img where tousuid=" + parent_id + "";
    var dt = BaseDal.QueryDataTable(sql);
    if (dt.Rows.Count == 0)
    {
    dict.Add("attach_url", img);
    dict.Add("attach_name", img_title);
    dict.Add("tousuid", parent_id);
    JngsDal.InsertToTable("tousu_img", dict);
    jd["result"].Add("filehtml/" + FileServerName);

    }
    else {

    dict.Add("attach_url", img);

    JngsDal.UpdateTables("tousu_img", dict, "tousuid=" + parent_id);
    jd["result"].Add("filehtml/" + FileServerName);
    }

    }

    }
    catch (Exception ex)
    {
    JngsDal.RecordError("fileupload", ex.Message);
    }
    }
    }
    }

    catch (Exception ex)
    {
    JngsDal.RecordError("fileupload1", ex.Message);
    }

    return jd.ToJson();
    }
    }
    }

  • 相关阅读:
    centos7下部署nginx+supervisor+netcore2.1服务器环境
    centos6.1配置nodejs运行环境
    centos下远程访问redis端口配置
    如何成为一名合格的软件测试师
    Maven之安装及构建简单项目 掠影
    JAVA语言单元测试框架——JUnit浅析
    软件测试 之 白盒测试 掠影
    软件测试 之 黑盒测试 掠影
    以一个闰年检测程序为例的非法字符异常输入检测
    学习心得——测试框架浅析
  • 原文地址:https://www.cnblogs.com/guo970910/p/9820538.html
Copyright © 2020-2023  润新知