index.php
923 Bytes
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
<?php
use yii\bootstrap\ActiveForm;
use yii\bootstrap\Html;
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
echo $form->field($model, 'imageFile')->fileInput(['multiple' => 'multiple']);
?>
<img id="blah" src="#" alt="your image">
<div class="form-group">
<?= Html::submitButton(Yii::t('app', 'Create'), ['class' => 'btn btn-success']) ?>
</div>
<?php
ActiveForm::end();
?>
<script>
function readURL(input) {
if (input.files && input.files[1]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah')
.attr('src', e.target.result)
.width(150);
};
reader.readAsDataURL(input.files[1]);
}
}
$(function() {
$(document).on('change', 'input[type=file]', function() {
readURL(this);
});
});
</script>