1

I need to change selected files in input:file element with Jquery. Firstly, user select files. There is a file size control in input:file change event. So, if control return false selected file should be removed in file_list. I searched this and try something for 3 - 4 hours. But not achieved still. I hope someone can help me.

Here is my function.

function handleFiles2() {

    var names = [];
    var newList = [];
    var text = '';
    var x = 0;
    var fsize = 0;
    var files =  $(".fileUpBasvuru").get(0).files;

    for (var i = 0; i < files.length; ++i) {

        fsize = parseInt(files[i].size);


        if (fsize > 102400) {

            newList.push(files.item(i));
            names.push(files[i].name);

        }
    }

    $(".fileUpBasvuru").get(0).files = newList;
    $(".file_list").html(text);

};
Yasin Yörük
  • 1,500
  • 7
  • 27
  • 51
  • Why are you (properly) using `get(0)` to access the underlying DOM element the first time, but not the second? (Although I'm pretty sure the `files` property is read-only, so you won't succeed anyway). – Frédéric Hamidi Feb 06 '15 at 16:14
  • yes you're right. I saw that and change my code but nothing changed. – Yasin Yörük Feb 06 '15 at 16:20
  • Yup, that would be the second part of my comment. Imagine you could modify the `files` property. You would be able not only to remove, but also to *add* files to the list. That would result in arbitrary files being uploaded *without the user's knowledge or consent*. That's why it's not possible. If you want to filter files, use the [`accept`](http://stackoverflow.com/q/181214/464709) attribute instead. – Frédéric Hamidi Feb 06 '15 at 16:22

0 Answers0