Custom file input does not show file name after upload
See original GitHub issueHi,
I am using the .custom-file-input class to customize the <input type='file'>
. It works as expected. I see that it is overlapping the default input element.
Issue: Typically the filename is displayed once we upload file. But here the label text is displayed even after uploading the file, i.e., Choose file should change to the uploaded filename.
Solution: I am able to see the file name if I change opacity:0
to opacity:1
from .custom-file-input class. We should be able to fetch the name of the file and replace the label name with the file name.
Below is the code I used:
<div class="custom-file">
<input type="file" class="custom-file-input" id="customFile">
<label class="custom-file-label" for="customFile">Choose file</label>
</div>
OS: Windows 10 and Android Oreo(8.1) Browser: Chrome Version 69.0.3497.100
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
bootstrap 4 file input doesn't show the file name - Stack Overflow
I have a problem with the custom-file-input class in Bootstrap 4. after I chose which file I want to upload the filename do...
Read more >Display file name in page after selecting file in file input
Insecure Resource. The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https....
Read more ><input type="file"> - HTML: HyperText Markup Language | MDN
When a file is chosen using an <input type="file"> , the real path to the source file is not shown in the input's...
Read more >How to customise a file upload control - Hidde's blog
To make a custom file upload control, use a standard file upload and label, then visually hide the input and style the label....
Read more >How to get file input by selected file name without path using ...
After that we will get the file name by using the jQuery change() method. This method is used in the JQuery to get...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @arun-awnics
It’s written here: https://getbootstrap.com/docs/4.1/components/forms/#file-browser our custom file input need a bit of JavaScript to work.
Bootstrap recommend this plugin: https://github.com/Johann-S/bs-custom-file-input
Hi @imayushshrivastava ,
You can use the below code which will definitely work for you:
$('#customFile').on('change', function(){ files = $(this)[0].files; name = ''; for(var i = 0; i < files.length; i++){ name += '\"' + files[i].name + '\"' + (i != files.length-1 ? ", " : ""); } $(".custom-file-label").html(name); });