Last active
March 27, 2017 16:56
-
-
Save SashaKolbasov/a583fc159a2951c5188e8ed4b4f78d54 to your computer and use it in GitHub Desktop.
Upload Photo/File
This file contains 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
<label class="attach attachInput"> | |
<span>Загрузите ваше фото</span> | |
<input type="file" name="photo" class="photo" accept="image/*" required /> | |
</label> |
This file contains 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
// GET PHOTO | |
$(function () { | |
var wrapper = $(".attachInput"), | |
inp = wrapper.find("input"), | |
lbl = wrapper.find("span"); | |
var file_api = (window.File && window.FileReader && window.FileList && window.Blob) ? true : false; | |
inp.change(function () { | |
var file_name = ""; | |
if (file_api && inp[0].files[0]) { | |
if (inp[0].files.length > 1) { | |
file_name = "Выбрано файлов: " + inp[0].files.length; | |
} else { | |
file_name = inp[0].files[0].name; | |
} | |
} else | |
file_name = inp.val().replace("C:\\fakepath\\", ''); | |
if (!file_name.length) return; | |
lbl.text(file_name); | |
}).change(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment