I have a pretty standard form to submit an image:
<form enctype="multipart/form-data" class="form-horizontal" role="form" method="POST">
<input id="image" name="image" type="file"/>
</form>
I want to be able to drag an image to an area so it will selected as the input.
I have researched on the internet how to do such simple task but I only get overdone plug-ins that use AJAX which sadly is not an option for this form. Anyone knows how to do this?
just drag your image into a input. if you need some information how to work with the result (link / title / src or something like that) of your droped image just visit this site.
function handleFileSelect(evt) {
evt.stopPropagation();
evt.preventDefault();
var files = evt.dataTransfer.files; // FileList object.
// files is a FileList of File objects. List some properties.
var output = [];
for (var i = 0, f; f = files[i]; i++) {
output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ',
f.size, ' bytes, last modified: ',
f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a',
'</li>');
}
document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
}
function handleDragOver(evt) {
evt.stopPropagation();
evt.preventDefault();
evt.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
}
// Setup the dnd listeners.
var dropZone = document.getElementById('drop_zone');
dropZone.addEventListener('dragover', handleDragOver, false);
dropZone.addEventListener('drop', handleFileSelect, false);
.example {
padding: 10px;
border: 1px solid #ccc;
}
#drop_zone {
border: 2px dashed #bbb;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
padding: 25px;
text-align: center;
font: 20pt bold 'Vollkorn';
color: #bbb;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="example">
<div id="drop_zone">Drop files here</div>
<output id="file_list2"></output>
</div>
<output id="list"></output>
<br>
<br>
<br>
<p> Easy solution </p>
<div class="intro-text">
<input class="" type="file" id="file-input" accept="image/*" capture="" name="files[]" multiple="">
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With