Example #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($id = false)
 {
     if ($id === false) {
         $model = new Picture();
     } else {
         $model = $this->loadModel($id);
     }
     $msg = '';
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Picture'])) {
         $model->attributes = $_POST['Picture'];
         $path = Options::getOption('imgPath') . '/' . date('Y') . '/' . date('m') . '/' . date('his') . '-';
         $model->image = $path . CUploadedFile::getInstance($model, 'image');
         if ($model->save()) {
             $pathTo = $_SERVER['DOCUMENT_ROOT'] . $model->image;
         }
         $pathFrom = $_FILES['Picture']['tmp_name']['image'];
         Controller::createPathUploadsNow();
         if (!copy($pathFrom, $pathTo)) {
             $msg = '<p style="color: red; margin: 5px; border: 1px solid red; text-align: center">Файл не был записан.</p>';
         } else {
             chmod($pathTo, 0777);
             $msg = '<p style="color: green; margin: 5px; border: 1px solid green; text-align: center">Файл был записан.</p>';
         }
     }
     $this->render('create', array('model' => $model, 'msg' => $msg));
 }