Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the file name for an input of file type in IE8

So background is I need to create a file upload control that submits files in a very specific fashion. Most users are on IE8 so I using a hidden iframe and a form post, but when the user selects the file using the file input my function kicks off. I don't know how to retrieve just file name in IE8 since the file api is not supported. In the example below the alert will output the full address, but this is not useful to me. Any ideas?

<form>
     <input name="data" id="filesInput" onchange="handleFileSelect(this);" type="file" value=""/>
</form>

function loadFile(evt){
     alert(evt.value);
}
like image 939
silvster27 Avatar asked Jan 28 '26 10:01

silvster27


1 Answers

Doesn't evt.value contain the full filename, but having a fake path, something like

C:\fakepath\video.mp4

So, can you use:

var n = evt.target.value.substring(evt.target.value.lastIndexOf('\\') + 1);

Now n will contain just the filename.

like image 69
edoceo Avatar answered Jan 30 '26 05:01

edoceo