简体   繁体   English

为什么输入文件正在缓存旧上传的图像?

[英]Why input file is caching the old uploaded images?

I have bootstrap modal popup that pops up to enable user to select images to upload, So when the user chooses images I have javascript function that add new <div> containing the filename, then the user click save to save the images on the database, every thing is working except the input file is caching the old images and uploading them again with the newly selected images.我有弹出的bootstrap modal弹出窗口,使用户能够上传 select 图像,因此当用户选择图像时,我有javascript <div> ,然后单击用户保存到包含文件的新文件除了输入文件正在缓存旧图像并使用新选择的图像再次上传它们之外,一切都在工作。

<asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="functionalUpdatePanel">
                <ContentTemplate>
    <button title="إضافة مرفق" data-toggle="modal" class="uploadAttach" data-target="#myModal" ></button>

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria- 
                labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria- 
                hidden="true"> </button>
                <h4 class="modal-title" id="myModalLabel">إضافة مرفق</h4>
                </div>
                <div class="modal-body">
                <asp:Label ID="lblMessage" runat="server" ForeColor="Green" />                  

                    <h5 style="margin-right:45%;font-weight:bold;font- 
                      size:1.2em">اختر المرفق</h5>             

                    <div class="uploadBtnDiv">


                        <input 
             style="cursor:pointer;opacity:0;width:100%;height:100%"  
                    title="اختيار مرفق" type="file" id="myFile" name="myFile"   
                   multiple="multiple" />

                    </div>      

                    <br />
                    <br />

                </div>
                <div class="modal-footer">

                 <asp:UpdatePanel runat="server" UpdateMode="Conditional">
                                                <ContentTemplate>
                                                    <asp:Button style="width:100% 
                    !important;" Text="حفظ" title="إرسال المرفق" CssClass="btn 
                    btn-success" runat="server" ID="btnUpload" 
                     OnClick="btnUploadClick"      />
                                                 </ContentTemplate>
                                                <Triggers>
                                                    <asp:PostBackTrigger 
                     ControlID="btnUpload" />
                                                </Triggers>
                                            </asp:UpdatePanel>
                </div>
            </div> 
            </div> 
        </div> 
             </ContentTemplate>
                <Triggers>


                </Triggers>
            </asp:UpdatePanel>

and here is my java script function这是我的 java 脚本 function

  $(document).on('change', '#myFile:visible', function() {

    var files = $(this)[0].files;
    var newLine;

    for (var i = 0; i < files.length; i++) {

        newLine = "<div class='attach-line'>" +
                    "<div class='attach-name'>" +

            files[i].name.slice(0,25)+'...' +

            "<i    class='icon-trash remove attach-delete'></i>" +

                    "</div>" +
                      "<br/>"+   
                  "</div>";

        $("#myModal .modal-body").append(newLine);

        // Clone the file selector, assign the name, hide and append it
        $(this).clone().hide().attr('name', 'myFile[]').insertAfter($(this));

      }
      $(".remove").click(function(){
            $(this).parent(".attach-name").remove();
          });
});

and bellow is the code behind下面是后面的代码

 protected void btnUploadClick(object sender, EventArgs e)
        {

            DataTable dt = new DataTable();
            dt.Columns.Add("AppId", typeof(int));
            dt.Columns.Add("Bytes", typeof(byte[]));
            dt.Columns.Add("ImgNames", typeof(string));
            dt.Columns.Add("ImgType", typeof(string));
            dt.Columns.Add("DedicatedMemberId", typeof(int));


            for (int i = 0; i < Request.Files.Count; i++)
            {
                if (Request.Files[i] != null && Request.Files[i].ContentLength > 0)
                {

                    string fType = Request.Files[i].ContentType.Split('/')[1];
                    string fName = Path.GetFileName(Request.Files[i].FileName);
                    byte[] bytes = new BinaryReader(Request.Files[i].InputStream).ReadBytes(Request.Files[i].ContentLength);
                    dt.Rows.Add(Convert.ToInt32(hfAppId.Value), bytes, fName,
                        fType, Convert.ToInt32(ViewState["memberId"]));
                }
            }
            string outputStr = AppsOperations.UpdateAttach("إرفاق صورة جديدة", "الطلبات ", dt, User.Identity.Name);

            if (outputStr == "s")
            {

                string redirectStr = "AuditApp.aspx?seq=" + hfAttSeq.Value + "&&AppType=" + hfAppType.Value + "&&id=" + hfAppId.Value;
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('تم تحميل المرفق بنجاح');window.location='" + redirectStr + "';", true);

            }
            else if (outputStr == "f")

            {

                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('" + "تعذر تحميل المرفق" + "')", true);

            }

        }

i am able to find the answer, actually i use the same code in another page to cache images for the use so i removed this the bellow line from java script function我能够找到答案,实际上我在另一个页面中使用相同的代码来缓存图像以供使用,所以我从 java 脚本 function 中删除了以下行

$(this).clone().hide().attr('name', 'myFile[]').insertAfter($(this));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM