Skip to content

Instantly share code, notes, and snippets.

@SashaKolbasov
Last active March 27, 2017 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SashaKolbasov/a583fc159a2951c5188e8ed4b4f78d54 to your computer and use it in GitHub Desktop.
Save SashaKolbasov/a583fc159a2951c5188e8ed4b4f78d54 to your computer and use it in GitHub Desktop.
Upload Photo/File
<label class="attach attachInput">
<span>Загрузите ваше фото</span>
<input type="file" name="photo" class="photo" accept="image/*" required />
</label>
// 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