Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const img_max = 10;
- let reader = new FileReader();
- let files = []; // user photos stored here
- reader.onload = function (e) {
- $('#img_'+files.length).attr('src', e.target.result);
- $('#img_container_'+files.length).css('display', 'inline-block');
- };
- function readURL(input) {
- if (input.files && input.files[0]) {
- reader.readAsDataURL(input.files[0]);
- files.push(input.files[0]);
- }
- }
- $("#img_input").change(function() {
- if (files.length < img_max)
- readURL(this);
- });
- function deleteImg(index)
- {
- let cur, next;
- for (let c = index; c < img_max; c++)
- {
- cur = $('#img_'+c);
- next = $('#img_'+(c+1)).attr('src');
- if (next == null) {
- cur.attr('src', null);
- $('#img_container_'+c).hide();
- break;
- }
- cur.attr('src', next);
- }
- files.splice(index, 1);
- }
- $('#form').submit(function (e)
- {
- let input = ($('#img_input'))[0];
- for (let c = 0; c < files.length; c++)
- input.files[c] = files[c];
- return true;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement