Goal:
Upload image by clicking on <img>
instead of <input type="file">
(there will be 3 uploads, so its just 3 placeholders on page load, then once you click any placeholder, you choose a file, and this file gets to display in respective placeholder). What I have now:
HTML:
<div class="image-upload">
<label for="file_input1">
<img id="send_photo_img1" src="assets/images/index2.png"/>
</label>
<input id="file_input1" type="file"/>
</div>
CSS:
.image-upload > input
{
display: none;
}
.image-upload img
{
display: inline-block;
margin-right:6px;
width: 90px;
height: 90px;
cursor: pointer;
}
Jquery:
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#send_photo_img1')
.attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#send_photo_img1").change(function(){
readURL("#file_input1");
});
While scripts like plupload.js
or dropzone.js
do that, but they also got lots of stuff I don't really need (i.e. UI that is not quite fitting my need or lots of code options not really needed, but taking space), so trying to implement this in scope required for my current needs.
The current code only lets me choose the desired img, but not display it. Currently, once the image is chosen, the loading sign is displayed for some time, but nothing happens afterward. No error output in Chrome F12 also.