Removing items from multiple file input

I can select multiple files using the multiple property in the file input tag. however, I am wondering how to remove one item.

I know that you cannot manipulate the input file yourself because its security hole and these browsers do not allow this, but I would like to point you to the jquery download plugin: https://github.com/blueimp/jQuery-File- Upload .

This plugin allows you to delete individual elements, there is no flash. all this is javascript and html5 api!

oh, and I know uploadify, I just want to stay with a clean js and html api file.

+4
source share
1 answer

EDIT:

After a better understanding of what you were looking for, I hacked another Demo where (from your JS) you can access the elements individually.

What I did was use the File API and File Readers :

  • Add an event handler to the input: $("#fileInput").on("change", processFiles);​

  • In your event handler: event.target.files to access the FileList Object

  • Use FileReader: var reader = new FileReader(); to read a file

  • You can read files in several ways (binary, text, URL, etc.), I chose the data URL: reader.readAsDataURL(file);

  • Add callback from FileReader reader.onload = function(){...};

  • In the callback, push the result: event.target.result into an array

From there you can do whatever you want!

I just sent the data to the echo server and then created the links with the answers, Check It .

+5
source

Source: https://habr.com/ru/post/1433679/


All Articles