any way you can add options to restrict uploads to only images? or maybe include this code via demos...
I believe this is what you're looking for: http://www.w3schools.com/tags/att_input_accept.asp
I'll throw that tag on the file input. Not a lot of time was spent in the upload demo, it's definitely not implemented with the best practices. But I suppose there's no harm in improving it.
try this!!!...
$( document ).ready(function() {
var $uploadCrop;
function readFile(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
result = e.target.result;
arrTarget = result.split(';');
tipo = arrTarget[0];
if (tipo == 'data:image/jpeg' || tipo == 'data:image/png') {
$uploadCrop.croppie('bind', {
url: e.target.result
});
$('.upload-demo').addClass('ready');
} else {
alert('Accept only .jpg o .png image types');
}
}
reader.readAsDataURL(input.files[0]);
}
}
$uploadCrop = $('#upload-demo').croppie({
viewport: {
width: 200,
height: 200,
type: 'square'
},
boundary: {
width: 300,
height: 300
}
});
$('#upload').on('change', function () { readFile(this); });
$('.upload-result').on('click', function (ev) {
$uploadCrop.croppie('result', {
type: 'canvas',
size: 'viewport',
quality: 0.8
}).then(function (resp) {
$('#imagebase64').val(resp);
$('#form').submit();
});
});
});
...
Most helpful comment
try this!!!...
$( document ).ready(function() {
var $uploadCrop;
});
...