Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2013
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Internet Explorer Send only filename while posting form with input file

    Hi,

    I have one HTML page containing one form as given below and a javascript to submit that form. When I submit that form, in wireshark I can see that it is sending filename as entire path to the file selected but I want only filename to be passed. I am trying this with IE9.

    Code:
    function onSubmit()
    {
    	if(document.getElementById("myfile").value != "") 
    	{
    		var frm = document.forms["myForm"];
    		frm.setAttribute("method","post");
    		frm.encoding = "multipart/form-data";
    		document.forms["myForm"].submit();
    		
    		return true;
    	}
    	else
    	{
    		alert("Please select a file.");
    		return false;
    	}
    }
    <form id="myForm" >
        <input type="file" name="myfile" id="myfile" size="30" />
        <input type="button" onclick="return onSubmit()" id="btnSubmit" value="Submit" />
    </form>
    Wireshark log looks like below,
    Code:
    Content-Disposition: form-data; name="myfile"; filename="c:\image.jpg"
    Content-Type: application/x-gzip-compressed
    .................
    How can I achieve this?

    Thanks,
    Jdp

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,212
    Thanks
    15
    Thanked 253 Times in 253 Posts
    I believe javascript has a function called lastIndexOf() that you that you could use to strip out the filename. lastIndexOf('/'); but you could probably get it server side, I know that in php it's in the $_FILES array. With javascript just set it as the value of a hidden input.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #3
    New Coder
    Join Date
    May 2013
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks DrDOS for your reply,

    Actually on server side that change would be done but more to that I want to do change from client side too.

    I checked on other machine having IE8 and IE9 but they are just sending filename instead of entire path.
    Code:
    Content-Disposition: form-data; name="myfile"; filename="image.jpg"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •