File upload Beta - Best Custom Product Options

File upload Beta

Regular price $29.99 Sale

This is our file upload beta code.

Add this code to the theme.liquid file after the <head> tag. Here is more info on editing theme code.

<script>
function update_upload() {
if ($('#bcpo input[type="file"]').length > 0) {
$.each($('#bcpo input[type="file"]'), function (k, v) {
$(v).css({opacity: 0, position: 'absolute', clip: 'rect(0,0,0,0)'});
$('<img class="upload_photo_box" style="display:none;border: solid 1px #333;" width=200>').insertBefore(v);
$('<button type="button" class="btn btn--wide upload-btn">Upload</button>').insertAfter(v);

$(v).change(function () {
var input = this;
var url = $(this).val();
var ext = url.substring(url.lastIndexOf('.') + 1).toLowerCase();
if (input.files && input.files[0]&& (ext == "gif" || ext == "png" || ext == "jpeg" || ext == "jpg")) {
var reader = new FileReader();
reader.onload = function (e) {
$(v).siblings('img').attr('src', e.target.result).css({display: 'block', marginBottom: 5});
}
reader.readAsDataURL(input.files[0]);
}

});

});

$('.upload-btn').click(function () {
$(this).siblings('input[type="file"]').click();
});

$(document).on('click', '.example-btn', function () {
$('#example-box').dialog({
resizable: true,
modal: true,
height: 'auto',
width: 'auto',
modal: true
});

});

window.clearInterval(set_int);
}
}
var set_int = setInterval('update_upload()', 1000);
</script>