artiom-75,
<input id="img_file" type="file" onchange="readURL(this)"><br>
<img id="img_prev" width="150" src="" alt="Preview">
<script>
function readURL(input) {
var type = ['image/bmp','image/gif','image/jpg','image/jpeg','image/png'];
var width = 1024;
var height = 768;
var size = 524288; // bytes
var file = input.files[0];
var prev = document.getElementById('img_prev');
function errMsg(x) {
alert('Error ' + x);
prev.src = '';
input.value = '';
}
if (type.indexOf(file.type) == -1) {
errMsg('Type');
return false;
} else if (file.size > size) {
errMsg('Size');
return false;
} else {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function(e) {
var img = new Image();
img.src = e.target.result;
img.onload = function() {
if (this.width <= width && this.height <= height) {
prev.src = this.src;
} else {
errMsg('Width/Height');
}
};
};
}
}
</script>