/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Carrusel(); $up = new UploadPhoto(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Carrusel'])) { $file = dirname(Yii::app()->request->scriptFile) . DIRECTORY_SEPARATOR . 'images/carrusel' . DIRECTORY_SEPARATOR . $model->ruta; if (isset($file)) { while (is_file($file) == TRUE) { unlink($file); } $up->foto = CUploadedFile::getInstance($up, 'foto'); if ($up->foto != "") { $nombreArchivo = str_replace(" ", "_", $up->foto); $nombreArchivo = str_replace("ñ", "n", $nombreArchivo); $nombreArchivo = str_replace("á", "a", $nombreArchivo); $nombreArchivo = str_replace("é", "e", $nombreArchivo); $nombreArchivo = str_replace("í", "i", $nombreArchivo); $nombreArchivo = str_replace("ó", "o", $nombreArchivo); $nombreArchivo = str_replace("ú", "u", $nombreArchivo); $nombreArchivo = str_replace("Á", "A", $nombreArchivo); $nombreArchivo = str_replace("É", "E", $nombreArchivo); $nombreArchivo = str_replace("Í", "I", $nombreArchivo); $nombreArchivo = str_replace("Ó", "O", $nombreArchivo); $nombreArchivo = str_replace("Ú", "U", $nombreArchivo); $nombreArchivo = date("Ymd_Gi") . "_" . $nombreArchivo; $file = dirname(Yii::app()->request->scriptFile) . DIRECTORY_SEPARATOR . 'images/carrusel' . DIRECTORY_SEPARATOR . $nombreArchivo; $model->attributes = $_POST['Carrusel']; $model->ruta = $nombreArchivo; //echo '<pre>'; print_r($_POST); echo '</pre>'; //echo '<pre>'; print_r($model->attributes); echo '</pre>'; //echo '<pre>'; print_r($up->attributes); echo '</pre>'; try { if ($up->foto->saveAs($file) && $model->save()) { $this->redirect(array('index')); } } catch (Exception $e) { echo $e->getMessage(); } } } else { $model->attributes = $_POST['Carrusel']; if ($model->save()) { $this->redirect(array('index')); } } } $this->render('create', array('model' => $model, 'up' => $up)); }