-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage_preview.php
75 lines (53 loc) · 2.07 KB
/
image_preview.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!-- Single Image -->
<form>
<input type="file" onchange="preview()">
<img id="frame" src="" class="d-none" width="100px" height="100px"/>
</form>
<script>
function preview() {
frame.classList.remove("d-none");
frame.src=URL.createObjectURL(event.target.files[0]);
}
</script>
<!-- Single Image -->
<input type="file" name="product_thambnail" class="form-control" onChange="mainThamUrl(this)" >
<img src="" id="mainThmb">
<script type="text/javascript">
function mainThamUrl(input){
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e){
$('#mainThmb').attr('src',e.target.result).width(80).height(80);
};
reader.readAsDataURL(input.files[0]);
}
}
</script>
<!-- Multiple Image -->
<input type="file" name="multi_img[]" class="form-control" multiple="" id="multiImg" >
<div class="row" id="preview_img"></div>
<script>
$(document).ready(function(){
$('#multiImg').on('change', function(){ //on file input change
if (window.File && window.FileReader && window.FileList && window.Blob) //check File API supported browser
{
var data = $(this)[0].files; //this file data
$.each(data, function(index, file){ //loop though each file
if(/(\.|\/)(gif|jpe?g|png)$/i.test(file.type)){ //check supported file type
var fRead = new FileReader(); //new filereader
fRead.onload = (function(file){ //trigger function on successful read
return function(e) {
var img = $('<img/>').addClass('thumb').attr('src', e.target.result) .width(80)
.height(80); //create image element
$('#preview_img').append(img); //append image to output element
};
})(file);
fRead.readAsDataURL(file); //URL representing the file's data.
}
});
}else{
alert("Your browser doesn't support File API!"); //if File API is absent
}
});
});
</script>