asp.net mvc 上传文件

xiaoxiao2021-02-28  35

前台:

<form action="../ryjbxx_tj" id="form2" method="post" enctype="multipart/form-data">                                <input type="text" id="div51_rybm" name="div51_rybm" value="" style="display: none;" />                                <table style="width: 100%;">                                    <tbody>                                        <tr>                                            <td class="td2">                                                <b>所属组织</b>                                                <input id="sszz" οnclick="click4()" type="text" value="" style="width: 140px;" readonly="readonly" />                                                <input id="sszzbm" name="sszzbm" type="text" value="" style="width: 40px; display: none;" />                                                <div id="treeview5" style="height: 200px; width: 250px; overflow: auto; position: absolute; display: none;"></div>                                            </td>                                            <td class="td2">                                                <b>姓名  </b>                                                <input id="xm" name="xm" type="text" value="" style="width: 140px;" readonly="readonly" />                                            </td>                                            <td class="td2" rowspan="3">                                                <img id="img3" style="width: 54px; height: 60px; margin-bottom: 5px;" />                                                <input id="file1" name="file1" type="file" />                                            </td>                                        </tr>                                                                            </tbody>                                </table>                                <div style="text-align: center; padding: 10px;">                                    <button οnclick="tj()" type="button" class="btn btn-primary">提交</button>                                </div>                            </form>

后台:

 HttpPostedFileBase file1 = Request.Files["file1"];                FileInfo fi = new FileInfo(file1.FileName);                //file1.SaveAs(Server.MapPath("~/UploadFile/"+file1.FileName));                string wjj = DateTime.Now.ToString("yyyyMMdd");                if (Directory.Exists(Server.MapPath("../UploadFile/images/" + wjj)) == false)//如果不存在就创建file文件夹                {                    Directory.CreateDirectory(Server.MapPath("../UploadFile/images/" + wjj));                }                string wjm = DateTime.Now.ToString("yyyyMMddHHmmssffffff");                string file3 = "../UploadFile/images/" + wjj + "/" + wjm + fi.Extension;                file1.SaveAs(Server.MapPath(file3));                file2 = ",img1='" + file3 + "' ";

转载请注明原文地址: https://www.6miu.com/read-2619977.html

最新回复(0)