zoukankan      html  css  js  c++  java
  • 上传图片

    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();
    }
    }
    }

  • 相关阅读:
    【总结+计划】七八月份总结+九月份计划——未知的状态最可怕
    【总结+计划】六月份总结+七月份计划——实习 就业 自学
    【计划】六月自学计划
    【总结】五月份总结——到底前端还是后台好呢
    Android中如何让DialogFragment全屏
    有用的
    Android Studio多渠道打包的使用
    adb not responding的解决方案
    ButterKnife的使用
    程序中判断android系统版本
  • 原文地址:https://www.cnblogs.com/guo970910/p/9820538.html
Copyright © 2011-2022 走看看