<input type=‘file’> for IE gives full path, need file name only

前端 未结 7 1162
眼角桃花
眼角桃花 2020-11-29 04:20

When perform uploading from IE browser, that my backend(org.apache.commons.fileupload) gets full file path.

For other non-IE browsers it gets filename and it\'s OK b

7条回答
  •  孤街浪徒
    2020-11-29 05:17

    You are interested in a UI approach.
    You could add a hidden input-field (or JSON entry) that contains just the bare file-name, populated by javascript.

    Using the following cross-browser(including IE)/platform javascript function (taken from my answer here, with full explanation and reference), which gets the filename only:

    function extractFilename(s){ 
      // returns string containing everything from the end of the string 
      //   that is not a back/forward slash or an empty string on error
      //   so one can check if return_value===''
      return (typeof s==='string' && (s=s.match(/[^\\\/]+$/)) && s[0]) || '';
    } 

提交回复
热议问题