<?php /* @var $this MyGalleryController */ /* @var $model MyGallery */ /* @var $form CActiveForm */ ?> <div class="form"> <?php $form = $this->beginWidget('CActiveForm', array( 'id' => 'my-gallery-form', 'htmlOptions' => array( 'enctype' => 'multipart/form-data' ), 'enableAjaxValidation' => false, )); ?> <?php echo $form->errorSummary($model); ?> <div class="row"> <?php echo $form->labelEx($model, 'description'); ?> <?php echo $form->textField($model, 'description', array('size' => 60, 'maxlength' => 255)); ?> <?php echo $form->error($model, 'description'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'img_url'); ?> <div id="dropZed" class="dropzone"></div> <?php echo $form->error($model, 'img_url'); ?> </div> <div class="row buttons"> <?php echo CHtml::submitButton($model->isNewRecord ? 'Создать' : 'Сохранить', array( 'name'=>'submit', 'id' => 'sb-all' )); ?> </div> <script> $(function() { var dzone = new Dropzone("#dropZed", { paramName: "file", url: "/admin/MyGallery/ImagesUpload", autoProcessQueue: false, addRemoveLinks: true, init: function() { var submitButton = document.querySelector("#sb-all"); dzone = this; // closure submitButton.addEventListener("click", function() { dzone.processQueue(); }); } }); Dropzone.autoDiscover = false; });; </script> <?php $this->endWidget(); ?> </div><!-- form --> 

here is the controller

 public function actionImagesUpload(){ $tml_name = $_FILES['file']['tmp_name']; $name = $_FILES['file']['name']; move_uploaded_file($tml_name, '/img/upload/' . '13' . $name); return $name; } public function actionCreate() { $model = new MyGallery; if (isset($_POST['MyGallery'])) { $model->attributes = $_POST['MyGallery']; $model->img_url = MyGalleryController::actionImagesUpload(); if ($model->save()) $this->redirect(array('view', 'id' => $model->id)); } $this->render('create', array( 'model' => $model, )); } 

MyGalleryController::actionImagesUpload() - $ name returns, and $ name is $_FILES['file']['name] but the error is undefined index file. How so?

  • Oh, I forgot, I decided to install the dropzone on yii / - AlexanderKim
  • There may be an array of files, in which case the structure will be slightly different. In any case, use CUploadedFile. - etki
  • Run the debug method actionImageUpload() or check what lies in the $_FILES array using the print_r($_FILES); functions print_r($_FILES); or var_dump($_FILES); - wapplay

0