ie javascript form submit with file input

后端 未结 8 525
-上瘾入骨i
-上瘾入骨i 2020-12-02 17:35

I have a html form, with a custom file upload field. And by that I mean that I have moved the actual file field beyond the borders of the page with css, that I have a custom

相关标签:
8条回答
  • 2020-12-02 18:10

    I found a weird solution to solve this problem.

    It thought about the js click thread. If it goes out of this thread, there no more security issues.

    I chose to use window.setTimeout. see sample below:

    <script type="text/javascript">
    
        $(function () {
            $("#<%= this.fuDoc.ClientID %>").bind('change', uploadFile);
            $("#<%= this.btnUpload.ClientID %>").click(chooseFile);
        });
    
        function chooseFile() {
            $("#<%= this.fuDoc.ClientID %>").click();
        }
    
        function uploadFile() {
            var fu = $("#<%= this.fuDoc.ClientID %>");
            if (fu.val() != "") {
                window.setTimeout(function () { 
                    <%= this.ClientScript.GetPostBackEventReference(this.btnUpload, "") %>; 
                }, 100);
            }
        }
    
    </script>
    
    <asp:FileUpload ID="fuDoc" runat="server" style="display: none;" />
    
    <asp:Button runat="server" ID="btnUpload" Text="upload" OnClick="btnUpload_Click" />
    
    <asp:Label ID="lbltext" Text="" runat="server" />`
    

    then, no more acces denied!

    0 讨论(0)
  • 2020-12-02 18:12

    I found the answer myself, After 2 days of crazy trial&error. I hope I can help somebody with this..

    I removed the hidden file input field from my coldfusion page and replaced it by an iframe tag. That iframe tag linked to another coldfusion page, containing another form with the removed file input field. Now when I use javascript to click the file input field, which is still hidden from view, it still gives the browse file dialog without a hitch. But when I use javascript to submit the form, through the iframe, miraculously, it submits the form in the iframe, making it possible to upload the file in some serverside scripting of your preference.

    iframe code:

    <form id="formFileUpload" class="formFileUpload" name="formFileUpload" method="post" action="../actions/act_upload_file.cfm" autocomplete="off" enctype="multipart/form-data">
        <input type="file" class="buttonFileHidden" id="inputFile" name="partnersLogo" />
    </form>
    

    iframe itself:

    <iframe src="admin/dsp_file_upload.cfm" id="ifu" name="ifu" class="buttonFileHidden">
    </iframe>
    

    javascript click & submit:

    ifu.document.formFileUpload.partnersLogo.click();
    ifu.document.formFileUpload.submit();
    
    0 讨论(0)
提交回复
热议问题