/** * @inheritdoc */ public function run() { if ($this->hasModel()) { $field = Html::activeFileInput($this->model, $this->attribute, $this->options); } else { $field = Html::fileInput($this->name, $this->value, $this->options); } echo $this->renderTemplate($field); $this->registerPlugin(); }
public function run() { if (is_null($this->imageOptions)) { $this->imageOptions = ['class' => 'img-responsive']; } $this->imageOptions['id'] = Yii::$app->getSecurity()->generateRandomString(10); $inputField = Html::getInputId($this->model, $this->attribute); $class = \yii\helpers\StringHelper::basename(get_class($this->model)) . 'Cutter'; echo Html::beginTag('div', ['class' => 'image-cutter', 'id' => $inputField . '-cutter']); echo Html::activeFileInput($this->model, $this->attribute); echo Html::hiddenInput($class . '[' . $this->attribute . ']', $this->model->{$this->attribute}); $previewImage = Html::beginTag('div', ['class' => 'img-container']); $previewImage .= Html::tag('span', '', ['class' => 'helper']); $previewImage .= Html::tag('span', Yii::t('sadovojav/cutter/cutter', 'Click to upload image'), ['class' => 'message']); $previewImage .= Html::img($this->model->{$this->attribute} ? $this->model->{$this->attribute} : null, ['class' => 'preview-image']); $previewImage .= Html::endTag('div'); echo Html::label($previewImage, Html::getInputId($this->model, $this->attribute), ['class' => 'dropzone']); echo Html::checkbox($class . '[' . $this->attribute . '-remove]', false, ['label' => Yii::t('sadovojav/cutter/cutter', 'Remove')]); Modal::begin(['header' => Html::tag('h4', Yii::t('sadovojav/cutter/cutter', 'Cutter'), ['class' => 'modal-title']), 'closeButton' => false, 'footer' => $this->getModalFooter($inputField), 'size' => Modal::SIZE_LARGE]); echo Html::beginTag('div', ['class' => 'image-container']); echo Html::img(null, $this->imageOptions); echo Html::endTag('div'); echo Html::tag('br'); echo Html::beginTag('div', ['class' => 'row']); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Aspect ratio'), $inputField . '-aspectRatio'); echo Html::textInput($class . '[' . $this->attribute . '-aspectRatio]', isset($this->cropperOptions['aspectRatio']) ? $this->cropperOptions['aspectRatio'] : 0, ['id' => $inputField . '-aspectRatio', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Angle'), $inputField . '-dataRotate'); echo Html::textInput($class . '[' . $this->attribute . '-cropping][dataRotate]', '', ['id' => $inputField . '-dataRotate', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Position') . ' (x)', $inputField . '-dataX'); echo Html::textInput($class . '[' . $this->attribute . '-cropping][dataX]', '', ['id' => $inputField . '-dataX', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Position') . ' (y)', $inputField . '-dataY'); echo Html::textInput($class . '[' . $this->attribute . '-cropping][dataY]', '', ['id' => $inputField . '-dataY', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Width'), $inputField . '-dataWidth'); echo Html::textInput($class . '[' . $this->attribute . '-cropping][dataWidth]', '', ['id' => $inputField . '-dataWidth', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Height'), $inputField . '-dataHeight'); echo Html::textInput($class . '[' . $this->attribute . '-cropping][dataHeight]', '', ['id' => $inputField . '-dataHeight', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::endTag('div'); Modal::end(); echo Html::endTag('div'); $options = ['inputField' => $inputField, 'useWindowHeight' => $this->useWindowHeight, 'cropperOptions' => $this->cropperOptions]; $options = Json::encode($options); $this->view->registerJs('jQuery("#' . $inputField . '").cutter(' . $options . ');'); }
/** * @inheritdoc */ public function run() { $width = null; if ($this->thumbsEnabled) { $filename = $this->behavior->getThumbFilePath($this->attribute, $this->thumbProfileName); } else { $filename = $this->behavior->getUploadedFilePath($this->attribute); } if (is_readable($filename)) { list($width) = getimagesize($filename); } else { Yii::warning("Unable to read file: '{$filename}' referenced by '{$this->attribute}' in model {$this->model->className()}"); if (empty($this->previewOptions['style'])) { $this->previewOptions['style'] = ''; } $this->previewOptions['style'] .= ';display: none;'; } $previewOptions = ArrayHelper::merge(['id' => $this->id . '-thumb', 'width' => $width], $this->previewOptions); if (empty($previewOptions['class'])) { $previewOptions['class'] = ''; } $previewOptions['class'] .= ' img-responsive img-thumbnail'; if (isset($this->model->attributeLabels()[$this->attribute]) and !isset($previewOptions['alt'])) { $previewOptions['alt'] = $this->model->attributeLabels()[$this->attribute]; } if ($this->thumbsEnabled) { $url = $this->behavior->getThumbFileUrl($this->attribute, $this->thumbProfileName); } else { $url = $this->behavior->getImageFileUrl($this->attribute); } Html::addCssStyle($previewOptions, "background-image: url({$url})"); $image = Html::tag('div', '', $previewOptions); $fileInput = Html::activeFileInput($this->model, $this->attribute, ['id' => $this->id . '-input'] + $this->options); echo $this->render('index', compact('image', 'fileInput')); $this->getView()->registerJs(";(function(\$){\n var widget = \$('#{$this->id}');\n var fileInput = widget.find('input[type=file]');\n var preview = \$('#{$previewOptions['id']}');\n var button = fileInput.closest('.image-up-input-button');\n\n fileInput.on('change', function() {\n var selectedFile = this.files[0];\n\n if (selectedFile) {\n var reader = new FileReader();\n reader.readAsDataURL(selectedFile);\n reader.onload = function (e) {\n preview.css('background-image', 'url(' + e.target.result + ')');\n }\n\n preview.show();\n }\n });\n\n})(jQuery);"); $this->getView()->registerCss(<<<CSS #{$previewOptions['id']} { background-position: center; background-repeat: no-repeat; background-size: contain; } CSS ); }
/** * @inheritdoc */ public function run() { $input = $this->hasModel() ? Html::activeFileInput($this->model, $this->attribute, $this->options) : Html::fileInput($this->name, $this->value, $this->options); echo $this->render('uploadButton', ['input' => $input]); $this->registerClientScript(); }
public function run() { /* @var $model ActiveRecord|ImageUploaderBehavior */ $model = $this->model; /* @var $behavior ImageUploaderBehavior */ $behavior = $model->geImageBehavior(); $wigetId = $this->id; $img_hint = '<div class="hint-block">'; $img_hint .= 'Поддерживаемые форматы: ' . $behavior->getImageConfigParam('fileTypes') . '. Максимальный размер файла: ' . ceil($behavior->getImageConfigParam('maxFileSize') / 1024 / 1024) . 'мб.'; $img_hint .= '</div><!-- /.hint-block -->'; $imageVal = $model->getAttribute($behavior->getImageConfigParam('imageAttribute')); if (!$model->isNewRecord && !empty($imageVal)) { $img_hint .= '<div id="' . $wigetId . '" class="row">'; $img_hint .= '<div class="col-md-12">'; $img_hint .= Html::img($this->imageSrc, ['class' => 'pull-left uploaded-image-preview']); // $img_hint .= '<div class="pull-left" style="margin-left: 5px;">'; $img_hint .= '<div class="btn-group-vertical pull-left" style="margin-left: 5px;" role="group">'; $img_hint .= Html::a('Delete <i class="glyphicon glyphicon-trash"></i>', '#', ['onclick' => new JsExpression(' if (!confirm("Вы действительно хотите удалить изображение?")) { return false; } $.ajax({ type: "post", cache: false, url: "' . Url::to($this->deleteUrl) . '", success: function() { $("#' . $wigetId . '").remove(); } }); return false; '), 'class' => 'btn btn-danger']); if (!empty($this->cropUrl)) { Yii::$app->response->headers->add('Access-Control-Allow-Origin', '*'); $pluginOptions = $this->cropPluginOptions; $validatorParams = $behavior->getImageConfigParam('imageValidatorParams'); if (isset($validatorParams['minWidth'])) { $pluginOptions['minCropBoxWidth'] = $validatorParams['minWidth']; } if (isset($validatorParams['minHeight'])) { $pluginOptions['minCropBoxHeight'] = $validatorParams['minHeight']; } $img_hint .= Cropper::widget(['modal' => true, 'cropUrl' => $this->cropUrl, 'image' => ImageUploaderBehavior::addPostfixToFile($model->getImageSrc(), '_original'), 'aspectRatio' => $behavior->getImageConfigParam('aspectRatio'), 'pluginOptions' => $pluginOptions, 'ajaxOptions' => ['success' => new JsExpression(<<<JS function(data) { // Refresh image src value to show new cropped image var img = \$("#{$wigetId} img.uploaded-image-preview"); img.attr("src", img.attr("src").replace(/\\?.*/, '') + "?" + new Date().getTime()); } JS )]]); } $img_hint .= '</div><!-- /.btn-group -->'; $img_hint .= '</div><!-- /.col-md-12 -->'; $img_hint .= '</div><!-- /.row -->'; } $imgAttr = $behavior->getImageConfigParam('imageAttribute'); return Html::activeFileInput($model, $imgAttr) . $img_hint; }
/** * @inheritdoc */ public function run() { if ($this->enableClientScript) { $view = $this->getView(); JasnyBootstrapAsset::register($view); } return implode("\n", [Html::beginTag('div', ['class' => 'fileinput fileinput-new input-group', 'data-provides' => 'fileinput']), Html::beginTag('div', ['class' => 'form-control', 'data-trigger' => 'fileinput']), Html::tag('i', '', ['class' => 'glyphicon glyphicon-file fileinput-exists']), Html::tag('span', '', ['class' => 'fileinput-filename']), Html::endTag('div'), Html::beginTag('span', ['class' => 'input-group-addon btn btn-default btn-file']), Html::tag('span', $this->selectButtonTitle, ['class' => 'fileinput-new']), Html::tag('span', $this->changeButtonTitle, ['class' => 'fileinput-exists']), Html::activeFileInput($this->model, $this->attribute, $this->options), Html::endTag('span'), Html::a($this->removeButtonTitle, '#', ['class' => 'input-group-addon btn btn-default fileinput-exists', 'data-dismiss' => 'fileinput']), Html::endTag('div')]) . "\n"; }
/** * {@inheritdoc} */ public function run() { if ($this->hasModel()) { echo Html::activeFileInput($this->model, $this->attribute, $this->options); } else { echo Html::fileInput($this->name, $this->value, $this->options); } $this->registerClientScript(); }
/** * @param string $attribute * * @return string */ public function getInputField($attribute) { if ($this->inputType == 'textArea') { return Html::activeTextarea($this->model, $attribute, $this->inputOptions); } elseif ($this->inputType == 'file') { return Html::activeFileInput($this->model, $attribute, $this->inputOptions); } else { return Html::activeTextInput($this->model, $attribute, $this->inputOptions); } }
/** * Renders the input * * @return string */ protected function renderInput() { $options = ArrayHelper::merge($this->options, ['class' => ' ' . $this->id, 'data-type' => $this->attribute]); $script = '$(function () { $(\'input.' . $this->id . '\').dropzone({ \'value\': \'' . $this->value . '\' }) });'; $this->view->registerJs($script, View::POS_READY); return Html::activeFileInput($this->model, $this->attribute, $options); }
public function run() { $value = $this->model->{$this->attribute}; if ($value) { echo Html::img(rtrim($this->imagePrefix, '/') . '/' . $value, ['height' => 200, 'class' => 'thumbnail']); } echo Html::activeFileInput($this->model, $this->attribute); if ($value) { echo Html::activeHiddenInput($this->model, $this->attribute); } }
public function run() { if (is_null($this->imageOptions)) { $this->imageOptions = ['class' => 'img-responsive']; } $this->imageOptions['id'] = Yii::$app->getSecurity()->generateRandomString(10); $inputField = Html::getInputId($this->model, $this->attribute); echo Html::beginTag('div', ['id' => $inputField . '-cutter']); echo Html::activeFileInput($this->model, $this->attribute, ['class' => 'hide']); echo Html::beginTag('div', ['class' => 'preview-pane', 'style' => $this->model->{$this->attribute} ? 'display:block' : 'display:none']); echo Html::beginTag('div', ['class' => 'preview-container']); echo Html::img($this->previewImgSrc ? $this->previewImgSrc : $this->model->{$this->attribute}, ['class' => 'preview-image ' . $this->previewImgClass]); echo Html::endTag('div'); echo Html::endTag('div'); echo Html::checkbox($this->attribute . '-remove', false, ['label' => Yii::t('davfervaz/cutter', 'Remove photo')]); Modal::begin(['header' => Html::tag('h4', Yii::t('davfervaz/cutter', 'Select the cut area')), 'closeButton' => [], 'footer' => $this->getModalFooter($inputField), 'size' => Modal::SIZE_LARGE]); echo Html::beginTag('div', ['class' => 'image-container']); echo Html::img(null, $this->imageOptions); echo Html::endTag('div'); echo Html::tag('br'); echo Html::beginTag('div', ['class' => 'row']); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('davfervaz/cutter', 'ASPECT_RATIO'), $inputField . '-aspectRatio'); echo Html::textInput($this->attribute . '-aspectRatio', isset($this->cropperOptions['aspectRatio']) ? $this->cropperOptions['aspectRatio'] : 0, ['id' => $inputField . '-aspectRatio', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('davfervaz/cutter', 'ANGLE'), $inputField . '-dataRotate'); echo Html::textInput($this->attribute . '-cropping[dataRotate]', '', ['id' => $inputField . '-dataRotate', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('davfervaz/cutter', 'POSITION') . ' (X)', $inputField . '-dataX'); echo Html::textInput($this->attribute . '-cropping[dataX]', '', ['id' => $inputField . '-dataX', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('davfervaz/cutter', 'POSITION') . ' (Y)', $inputField . '-dataY'); echo Html::textInput($this->attribute . '-cropping[dataY]', '', ['id' => $inputField . '-dataY', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('davfervaz/cutter', 'WIDTH'), $inputField . '-dataWidth'); echo Html::textInput($this->attribute . '-cropping[dataWidth]', '', ['id' => $inputField . '-dataWidth', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('davfervaz/cutter', 'HEIGHT'), $inputField . '-dataHeight'); echo Html::textInput($this->attribute . '-cropping[dataHeight]', '', ['id' => $inputField . '-dataHeight', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::endTag('div'); Modal::end(); echo Html::endTag('div'); $view = $this->getView(); CutterAsset::register($view); $options = ['inputField' => $inputField, 'useWindowHeight' => $this->useWindowHeight, 'cropperOptions' => $this->cropperOptions]; $options = Json::encode($options); $view->registerJs('jQuery("#' . $inputField . '").cutter(' . $options . ');'); }
/** * @inheritdoc */ public function run() { if ($this->enableClientScript) { $view = $this->getView(); JasnyBootstrapAsset::register($view); } $previewParams = ['class' => 'fileinput-preview thumbnail', 'data-trigger' => 'fileinput']; if ($this->previewWidth and $this->previewHeight) { $previewParams['style'] = 'width: ' . $this->previewWidth . 'px; height: ' . $this->previewHeight . 'px;'; } return implode("\n", [Html::beginTag('div', ['class' => 'fileinput fileinput-new fileinput-image', 'data-provides' => 'fileinput']), Html::beginTag('div', $previewParams), Html::endTag('div'), Html::beginTag('div'), Html::beginTag('span', ['class' => 'btn btn-default btn-file']), Html::tag('span', $this->selectButtonTitle, ['class' => 'fileinput-new']), Html::tag('span', $this->changeButtonTitle, ['class' => 'fileinput-exists']), Html::activeFileInput($this->model, $this->attribute, $this->options), Html::endTag('span'), Html::a($this->removeButtonTitle, '#', ['class' => 'btn btn-default fileinput-exists', 'data-dismiss' => 'fileinput']), Html::endTag('div'), Html::endTag('div')]) . "\n"; }
public function run() { $this->registerAssets(); // Button to select & upload files echo '<span class="btn btn-success fileinput-button"><span>Select files...</span>'; //The file input field used as target for the file upload widget echo Html::activeFileInput($this->model, $this->attribute, ['name' => 'files[]']); echo '</span>'; //The global progress bar echo '<p>Upload progress</p>'; echo Progress::widget(['barOptions' => ['class' => 'progress-bar-success', 'aria-valuemax' => false, 'aria-valuemin' => false, 'role' => false, 'id' => 'bar'], 'options' => ['class' => false, 'id' => false]]); //The list of files uploaded echo '<p>Files uploaded:</p><ul id="files"></ul>'; }
/** * Запустить * процесс * @return string */ public function run() { $content = '<div class="c-file-block">'; $content .= Html::activeFileInput($this->model, $this->attribute, ['class' => 'styled']); if ($this->model->{$this->attribute} instanceof AttachFileModel && $this->model->{$this->attribute}->isExists()) { $size = $this->model->{$this->attribute}->getSize(); $buttonId = Html::getInputId($this->model, $this->attribute) . '-button'; $content .= '<div class="img-preview file-block"><div class="c-info"><span>'; $content .= '<a href="' . $this->model->{$this->attribute}->getDownloadLink() . '" class="buttonS bGreen bWhite">Завантажити ' . $size . '</a></span>'; $content .= '<div class="delete-row"><a class="buttonS bRed nsubmit delete-file" href="javascript:void(0);" id="' . $buttonId . '">Видалити</a></div></div></div>'; $this->getView()->registerJs("\$('#{$buttonId}').click(function(){\$(this).closest('.c-file-block').find('input[type=\"hidden\"]').val('remove');})"); } $content .= '</div>'; return $content; }
/** * Generates a form field. * A form field is associated with a model and an attribute. It contains a label, an input and an error message * and use them to interact with end users to collect their inputs for the attribute. * @param Model $model the data model * @param string $attribute the attribute name or expression. See [[Html::getAttributeName()]] for the format * about attribute expression. * @param array $options the additional configurations for the field object. These are properties of [[ActiveField]] * or a subclass, depending on the value of [[fieldClass]]. * @return string the created ActiveField object * @see fieldConfig */ public function imageField($model, $attribute, $options = []) { if ($model->{$attribute}) { $src = '@web/' . $model->{$attribute}; } else { $src = '@web/images/no_image.jpg'; } $imageField = ''; $imageField .= Html::activeLabel($model, $attribute, ['class' => 'col-sm-12 control-label']); $imageField .= Html::beginTag('label', ['for' => Html::getInputId($model, $attribute), ['class' => 'col-sm-8']]); $imageField .= Html::img($src, $options); $imageField .= Html::endTag('label'); $imageField .= Html::beginTag('span', ['class' => 'image-trash glyphicon glyphicon-remove-circle']); $imageField .= Html::endTag('span'); $imageField .= Html::activeFileInput($model, $attribute, ['style' => 'display:none']); $imageField .= Html::activeHiddenInput($model, 'removeImage', ['value' => '0']); return $imageField; }
/** * @inheritdoc */ public function run() { if ($this->hasModel()) { echo Html::activeFileInput($this->model, $this->attribute, $this->options); if (!$this->ratio || !$this->crop_field || !$this->url) { foreach ($this->model->getBehaviors() as $beh) { if (!empty($beh->attribute) && $beh->attribute == $this->attribute) { if ($beh instanceof CropImageUploadBehavior) { if (!$this->ratio && $beh->ratio) { $this->ratio = $beh->ratio; } if (!$this->crop_field && $beh->crop_field) { $this->crop_field = $beh->crop_field; } if (!$this->url && $beh->url) { $this->url = $beh->url; } break; } } } } if (!$this->crop_value && $this->crop_field) { $this->crop_value = $this->model->{$this->crop_field}; } } else { echo Html::fileInput($this->name, $this->value, $this->options); } $crop_id = false; if ($this->crop_field) { if ($this->hasModel()) { $crop_id = Html::getInputId($this->model, $this->crop_field); echo Html::activeHiddenInput($this->model, $this->crop_field, ['value' => $this->crop_value]); } else { $crop_id = $this->options['id'] . '_' . $this->crop_field; echo Html::hiddenInput($this->crop_field, $this->crop_value); } } if ($this->url) { $this->url = \Yii::getAlias($this->url); } $jsOptions = ['crop_value' => $this->crop_value, 'crop_id' => $crop_id, 'ratio' => $this->ratio, 'url' => $this->resolvePath($this->url), 'clientOptions' => $this->clientOptions, 'is_crop_prev' => $crop_id || !$this->hasModel() ? false : true, 'crop_class' => $this->crop_class]; $this->registerPlugin($jsOptions); }
/** * @var yii\web\View $this */ use yii\helpers\Html; ?> <h1>load/index</h1> <p> Yii2 <?php echo Html::beginForm('', 'post', ['enctype' => 'multipart/form-data']); ?> <?php echo Html::error($upload, 'file'); ?> <?php echo Html::activeFileInput($upload, 'file'); ?> <?php echo Html::submitButton('Upload'); ?> <?php Html::endForm(); ?> </p>
$cfg = $uploader->illustration; $aspect = $cfg->aspectRatio; if (!is_numeric($aspect)) { $model->setAttribute($aspect, 1000 * $model->getAttribute($aspect)); } ?> <div id="<?php echo $uploader->id; ?> " class="uploader"> <div class="cropper"></div> <div class="uploader-aspect"> <?php if (!is_numeric($aspect) && $uploader->aspectOptions) { echo $uploader->radio ? Html::activeRadioList($model, $aspect, $uploader->aspectOptions, ['class' => 'uploader-select', 'separator' => '<br />', 'itemOptions' => ['disabled' => 'disabled']]) : Html::activeDropDownList($model, $aspect, $uploader->aspectOptions, ['class' => 'form-control uploader-select', 'disabled' => 'disabled']); } ?> <?php echo $uploader->deleteOptions ? Html::activeCheckbox($model, "__{$attr}_delete__", array_merge($uploader->deleteOptions, ['disabled' => !$uploader->current, 'class' => 'del-switch'])) : ''; ?> </div> <div class="uploader-control"> <?php echo Html::activeFileInput($model, "__{$attr}_file__"); ?> <?php echo Html::activeHiddenInput($model, "__{$attr}_crop__"); ?> </div> </div>
use kartik\slider\Slider; use kartik\icons\Icon; Icon::map($this, Icon::FA); ?> <div id="<?php echo $idWidget; ?> " class="cropbox"> <div class="imageBox"> <div class="thumbBox"></div> </div> <p class="message"></p> <div class="btn-group"> <span class="btn btn-primary btn-file"> <?php echo Icon::show('folder-open') . Cropbox::t('Browse') . Html::activeFileInput($model, $attribute, $options); ?> </span> <?php echo Html::button(Icon::show('expand '), ['class' => 'btn btn-default btnZoomIn']); echo Html::button(Icon::show('compress'), ['class' => 'btn btn-default btnZoomOut']); echo Html::button(Icon::show('crop') . Cropbox::t('Crop'), ['class' => 'btn btn-success btnCrop']); ?> </div> <div class="form-horizontal"> <div class="form-group resizeWidth"> <label for="<?php echo $idWidget; ?> _cbox_resize_width" class="col-md-3"><?php echo Cropbox::t('Width');
/** * Renders a file input. * This method will generate the `name` and `value` tag attributes automatically for the model attribute * unless they are explicitly specified in `$options`. * @param array $options the tag options in terms of name-value pairs. These will be rendered as * the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]]. * * If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly. * * @return $this the field object itself. */ public function fileInput($options = []) { // https://github.com/yiisoft/yii2/pull/795 if ($this->inputOptions !== ['class' => 'form-control']) { $options = array_merge($this->inputOptions, $options); } // https://github.com/yiisoft/yii2/issues/8779 if (!isset($this->form->options['enctype'])) { $this->form->options['enctype'] = 'multipart/form-data'; } $this->adjustLabelFor($options); $this->parts['{input}'] = Html::activeFileInput($this->model, $this->attribute, $options); return $this; }
/** * Renders a file input. * This method will generate the "name" and "value" tag attributes automatically for the model attribute * unless they are explicitly specified in `$options`. * @param array $options the tag options in terms of name-value pairs. These will be rendered as * the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]]. * @return static the field object itself */ public function fileInput($options = []) { // https://github.com/yiisoft/yii2/pull/795 if ($this->inputOptions !== ['class' => 'form-control']) { $options = array_merge($this->inputOptions, $options); } $this->adjustLabelFor($options); $this->parts['{input}'] = Html::activeFileInput($this->model, $this->attribute, $options); return $this; }
/** * Загрузка изображений * @param array $rowParams * @param string $value * @return string */ public function UploadFiles($rowParams = [], $value = "", $item = [], $last_id = 0) { $params = $this->MakeRowParams($rowParams["params"]); $prefix = $rowParams["name"]; $model = new \app\models\UploadFile(); $pathDir = $params["path"]; $folderName = $value; $model->{$prefix} = ""; $model->imageRow = $prefix; unset($params["path"]); if (yii::$app->request->isPost) { $model_admin = new \app\base\ModelAdmin(); $folderName = !empty($value) ? $value : $model_admin->GetLastInsertId($rowParams["model_id"]); $model->path = $_SERVER["DOCUMENT_ROOT"] . $pathDir . $folderName . "/"; if (isset($params["multiple"]) && $params["multiple"] == "true") { $model->{$prefix} = UploadedFile::getInstances($model, $prefix); if ($model->uploadMultiple($params)) { return; } } else { $model->{$prefix} = UploadedFile::getInstance($model, $prefix); if ($model->uploadSingle($params)) { return; } } } $getFiles = app::I()->ReturnFilesDir($pathDir . $folderName . "/"); $tag = Html::label($rowParams["label"], $rowParams["name"]); if (count($getFiles) > 0) { if (isset($params["value"]) && !empty($params["value"])) { $file = app::I()->GetImageFromDir($pathDir . $folderName . "/" . $params["value"]); $tag .= Html::beginTag('div'); $tag .= Html::tag('div', Html::img($file, ["style" => "max-width:220px"])); if ($file) { $tag .= Html::a('Удалить', "javascript:void(0)", ["onclick" => "RemoveFile(this, '{$file}')"]); } $tag .= Html::endTag('div'); } else { foreach ($getFiles as $index => $file) { $file = app::I()->GetImageFromDir($pathDir . $folderName . "/" . $index); $tag .= Html::beginTag('div'); $tag .= Html::tag('div', Html::img($file, ["style" => "max-width:220px"])); if ($file) { $tag .= Html::a('Удалить', "javascript:void(0)", ["onclick" => "RemoveFile(this, '{$file}')"]); } $tag .= Html::endTag('div'); } } } if (isset($params["multiple"]) && $params["multiple"] == "true") { $tag .= Html::activeFileInput($model, "{$prefix}[]", ['multiple' => true]); } else { $tag .= Html::activeFileInput($model, $prefix); } return $tag; }
?> <label class="control-label"><?php echo $this->context->label; ?> </label> <?php } ?> <div class="input-group single-file-upload" style="display:<?php echo $inputDisplay; ?> "> <span class="input-group-btn"> <span class="btn btn-primary btn-file"> انتخاب <?php echo Html::activeFileInput($fileObject, "[{$uniqueId}]resource"); ?> </span> </span> <input type="text" class="form-control" readonly> </div> <?php echo Html::error($fileObject, 'resource', ['class' => 'help-block']); ?> <div class="uploaded-files"> <ul class="list-unstyled"> <?php foreach ($uploadedFiles as $file) { ?> <li>
?> <label class="control-label"><?php echo $this->context->label; ?> </label> <?php } ?> <div class="single-file-upload" style="display:<?php echo $inputDisplay; ?> "> <span class="file-input btn btn-block btn-primary btn-image"> انتخاب عکس <?php echo Html::activeFileInput($fileObject, "[{$uniqueId}]resource", ['id' => 'file-input-' . $uniqueId]); ?> </span> <img id="uploaded-image-<?php echo $uniqueId; ?> " src="#" alt="" style="display:none" class="thumbnail image-preview" /> <?php echo Html::error($fileObject, 'resource', ['class' => 'help-block']); ?> </div>
?> <?php //echo "----xxxx---->". print_r($options, true); ?> <!-- Redirect browsers with JavaScript disabled to the origin page --> <noscript><input type="hidden" name="redirect" value="http://blueimp.github.io/jQuery-File-Upload/"></noscript> <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload --> <div class="row fileupload-buttonbar"> <div class="col-lg-7"> <!-- The fileinput-button span is used to style the file input field as button --> <span class="btn btn-success fileinput-button"> <i class="glyphicon glyphicon-plus"></i> <span>Add files...</span> <?php echo Html::activeFileInput($model, $attribute, $options) . "\n"; ?> <!-- <input type="file" name="files[]" multiple> --> </span> <button type="submit" class="btn btn-primary start"> <i class="glyphicon glyphicon-upload"></i> <span>Start upload</span> </button> <button type="reset" class="btn btn-warning cancel"> <i class="glyphicon glyphicon-ban-circle"></i> <span>Cancel upload</span> </button> <button type="button" class="btn btn-danger delete"> <i class="glyphicon glyphicon-trash"></i> <span>Delete</span> </button>
/** * Renders the widget. */ public function run() { $this->registerClientScript(); if ($this->hasModel()) { $fieldName = $this->attribute; $value = $this->model->{$fieldName}; $image = ''; $checkbox = ''; if (isset($value)) { if ($value != '') { $image = Html::img($value, ['width' => 200, 'class' => 'thumbnail']); if (self::isSmall($value)) { $original = self::getOriginal($value); $image = Html::a($image, $original, ['target' => '_blank']); } $checkbox = $this->getCheckbox(); $checkbox .= Html::hiddenInput($this->valueNameAttribute, $value, ['id' => $this->valueIdName]); } } $options = ArrayHelper::getValue($this->options, 'inputFile', []); $input = Html::activeFileInput($this->model, $this->attribute, $options); } echo $this->renderTemplate(['image' => $image, 'checkbox' => $checkbox, 'input' => $input]); }
<?php // $context->model instanceof \yii\base\Model && $context->attribute !== null // ? Html::activeFileInput($context->model, $context->attribute, $context->fieldOptions) // : Html::fileInput($context->name, $context->value, $context->fieldOptions); ?> <!-- </span> --> <div class="file-upload"> <div class="div-file"> <input type="file"> <span class="btn-admin gray fileinput-button">Choose New File</span> <span class="text">No file chosen</span> </div> <button type="submit" class="btn-admin start">upload</button> <?php echo $context->model instanceof \yii\base\Model && $context->attribute !== null ? Html::activeFileInput($context->model, $context->attribute, $context->fieldOptions) : Html::fileInput($context->name, $context->value, $context->fieldOptions); ?> </div> <!-- <button type="submit" class="btn btn-primary start"> --> <!-- <i class="glyphicon glyphicon-upload"></i> --> <!-- <span>Start upload</span> --> <!-- </button> --> <!-- <button type="reset" class="btn btn-warning cancel"> --> <!-- <i class="glyphicon glyphicon-ban-circle"></i> --> <!-- <span>Cancel upload</span> --> <!-- </button> --> <!-- <button type="button" class="btn btn-danger delete"> --> <!-- <i class="glyphicon glyphicon-trash"></i> --> <!-- <span>Delete</span> --> <!-- </button> --> <!-- <input type="checkbox" class="toggle"> -->
?> </div> <div class="form-group"> <?php echo Html::activeLabel($model, 'og_url', $labelOptions); ?> <?php echo Html::activeTextInput($model, 'og_url', $inputOptions); ?> </div> <div class="form-group"> <?php echo Html::activeLabel($model, 'og_image', $labelOptions); ?> <?php echo Html::activeFileInput($model, '_image', $inputOptions); ?> <?php if ($ogImage = $model->ogImage) { ?> <?php echo Html::img($model->ogImage->image); ?> <?php } ?> </div> <div class="form-group"> <?php echo Html::activeLabel($model, 'og_sitename', $labelOptions); ?>
<?php if ($uploaded) { ?> <p> Файл успешно загружен. Проверьте <?php echo $dir; ?> . </p> <?php } ?> <?php echo Html::beginForm('', 'post', ['enctype' => 'multipart/form-data']); ?> <?php echo Html::error($model, 'file'); ?> <?php echo Html::activeFileInput($model, 'file'); ?> <?php echo Html::submitButton('Upload'); ?> <?php Html::endForm(); ?> </p>
?> " class="cropbox"> <div class="alert alert-info"></div> <div class="workarea-cropbox"> <div class="bg-cropbox"> <img class="image-cropbox"> <div class="membrane-cropbox"></div> </div> <div class="frame-cropbox"> <div class="resize-cropbox"></div> </div> </div> <div class="btn-group"> <span class="btn btn-primary btn-file"> <?php echo '<i class="glyphicon glyphicon-folder-open"></i> ' . Cropbox::t('Browse') . Html::activeFileInput($this->context->model, $this->context->attribute, $this->context->options); ?> </span> <?php echo Html::button('<i class="glyphicon glyphicon-scissors"></i> ' . Cropbox::t('Crop'), ['class' => 'btn btn-success btn-crop']); ?> <?php echo Html::button('<i class="glyphicon glyphicon-repeat"></i> ' . Cropbox::t('Reset'), ['class' => 'btn btn-warning btn-reset']); ?> </div> <div class="cropped"> <p> <?php if (!empty($this->context->originalImageUrl)) { echo Html::a('<i class="glyphicon glyphicon-eye-open"></i> ' . Cropbox::t('Show original'), $this->context->originalImageUrl, ['target' => '_blank', 'class' => 'btn btn-info']); }