Z
Z
z_u_l2020-04-22 14:07:48
JavaScript
z_u_l, 2020-04-22 14:07:48

Why, when uploading several photos, the name under the photo is the same?

I'm uploading multiple files.

Link to example

When several files with different names are selected, for some reason the name under the picture is the same, although the names of the photos are displayed correctly in the console. Why is this happening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Klimenko, 2020-04-22
@z_u_l

This is what a more or less correct version would look like:

$(() => {
    const imagesPreview = (input, container) => {
        if (input.files) {
            for (const file of input.files) {
                const reader = new FileReader();
                reader.onload = e => {
                    $($.parseHTML('<img>')).attr('src', e.target.result).appendTo(container);
                    $($.parseHTML('<div>')).text(file.name).appendTo(container);
                }
                reader.readAsDataURL(file);
            }
        }

    };
    $('#gallery-photo-add').on('change', e => imagesPreview(e.currentTarget, 'div.gallery'));
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question