Image upload preview remove option

I use this code below to upload images. The code itself is working fine. The user can select multiple image at once or just one by one. The code shows the selected image files with preview of the image before upload.

Is there an option to remove a selected file (image) before the upload? To add a “remove” button under the thumbnails?

 <h3>Add images</h3>
   <input type="file" id="files" name="file[]" multiple />
   <output id="list"></output>
   <button type="submit" name="upload">Save</button>
	 function handleFileSelect(evt) {
	 var files =;
	 for (var i = 0, f; f = files[i]; i++) {

	 if (!f.type.match('image.*')) {
	 var reader = new FileReader();

	 reader.onload = (function(theFile) {
	 return function(e) {
	 var span = document.createElement('span');
	 span.innerHTML = ['<img style="width:300px; border-width:3px; border-style:solid; border-color:#000; margin:8px;" src="',, '" title="', escape(, '"/>'].join('');
	document.getElementById('list').insertBefore(span, null);

	 document.getElementById('files').addEventListener('change', handleFileSelect, false);

Actually, you can’t select them one by one – the new selection will replace the old file list, only the thumbnails will stay on the page. I think your best bet would be to append a new file input after one file was selected, which you could then simply remove again when the corresponding button gets clicked; eventually only the files actually present in the form will get sent to the server.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.