A Pen by keshavdutt on CodePen.
Created
August 24, 2021 08:42
-
-
Save keshavdutt/4cced0a2f7b34bd1374104508cf15b9e to your computer and use it in GitHub Desktop.
Bootstrap 4 browse custom button with JQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container mt-5"> | |
<h1 class="text-center">Bootstrap 4 Upload multiple files</h1> | |
<div class="col-sm-12 col-lg-4 mr-auto ml-auto border p-4"> | |
<form method="post" enctype="multipart/form-data"> | |
<div class="form-group"> | |
<label><strong>Upload Files</strong></label> | |
<div class="custom-file"> | |
<input type="file" name="files[]" multiple class="custom-file-input form-control" id="customFile"> | |
<label class="custom-file-label" for="customFile">Choose file</label> | |
</div> | |
</div> | |
<div class="form-group"> | |
<button type="button" name="upload" value="upload" id="upload" class="btn btn-block btn-dark"><i class="fa fa-fw fa-upload"></i> Upload</button> | |
</div> | |
</form> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
$('input[type="file"]').on("change", function() { | |
let filenames = []; | |
let files = this.files; | |
if (files.length > 1) { | |
filenames.push("Total Files (" + files.length + ")"); | |
} else { | |
for (let i in files) { | |
if (files.hasOwnProperty(i)) { | |
filenames.push(files[i].name); | |
} | |
} | |
} | |
$(this) | |
.next(".custom-file-label") | |
.html(filenames.join(",")); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script> | |
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment