I'm using Bootstrap File Upload plugin writen by Krajee (http://plugins.krajee.com/file-input/plugin-options). I'm trying to get the name of the uploaded files. I didn't see a method for it. How can i manage ?
Asked
Active
Viewed 1,093 times
0
-
Where are you trying to get the name from, server or client? In the case of the client this should work for you https://stackoverflow.com/questions/857618/javascript-how-to-extract-filename-from-a-file-input-control but in case you are trying to get the name with a server side language we need to know what you're using – VladNeacsu Nov 09 '17 at 10:08
-
@VladNeacsu i'm trying to get them from the client side. The problem is this, as i'm using a jquery plugin to upload the file before submit the form with php, i would like the get the name of the uploaded file when i submit my form because i want to use them. – alexis Nov 09 '17 at 10:15
1 Answers
1
Looking in the Bootstrap File Upload docs (specifically the Events), I've found that when you upload a file it also loads a preview of it (if you have that option enabled). When that happens is that it emits the following event:
$('#input-id').on('fileloaded', function(event, file, previewId, index, reader) {
console.log("fileloaded");
});
The second parameter file
is actually a Javascript Object that has the name property, as the docs state here: https://developer.mozilla.org/en-US/docs/Web/API/File so you could try something like:
$('#input-id').on('fileloaded', function(event, file, previewId, index, reader) {
console.log(file.name);
});
More info here: https://developer.mozilla.org/en-US/docs/Web/API/File/name
Also, you could try to see if the change
event, that fires when you upload a file regardless of preview or not, has additional parameters (this is not in the docs):
$('#input-id').on('change', function(event) { // add the second parameter file
console.log("change"); // try to log file.name here and see if it works
});

VladNeacsu
- 1,268
- 16
- 33
-
You're welcome. Please consider reading this, as I see you're a new user https://stackoverflow.com/help/someone-answers – VladNeacsu Nov 23 '17 at 09:56