/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Obra(); $tra_obra = new TraObra(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Obra'])) { $model->attributes = $_POST['Obra']; $model->imagen = "0"; //echo count($_FILES['imagen']['name']); if ($model->validate() and count($_FILES['imagen']['name']) >= 1) { $idartista = $model->idartista; $idexpo = $model->idexposicion; $idiomaid = $model->idiomaid; $directorio = 'images/obra/originals/'; $porciones = explode("<br>", $model->descripcion); $porciones_tra = explode("<br>", $model->text_language); $i = 0; while ($i < count($_FILES['imagen']['name'])) { if ($i != 0) { $model = new Obra(); $tra_obra = new TraObra(); } $model->idiomaid = 2; // solo para que no valide al momento de insertar en el for. $model->text_language = "auxiliar"; $nombre = $this->NewGuid(); if ($_FILES['imagen']['type'][$i] == "image/jpeg") { $tipo = "jpg"; } else { $tipo = "png"; } $destino = $directorio . $nombre . '.' . $tipo; $model->imagen = $nombre . '.' . $tipo; $model->idexposicion = $idexpo; $model->idartista = $idartista; move_uploaded_file($_FILES['imagen']['tmp_name'][$i], $destino); $model->descripcion = $porciones[$i]; $model->save(); $tra_obra->idiomaid = $idiomaid; $tra_obra->obraid = $model->idobra; $tra_obra->descripcion = $porciones_tra[$i]; $tra_obra->save(); $i++; } $this->redirect(array('admin')); } } $this->render('create', array('model' => $model)); }