Advertisement
Guest User

create

a guest
Oct 22nd, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.87 KB | None | 0 0
  1. $model =new FactoryImages;
  2.         // Uncomment the following line if AJAX validation is needed
  3.          $this->performAjaxValidation($model);
  4.          $type = isset($_GET['type']) ? $_GET['type'] : 'post';
  5.          
  6.         if(isset($_POST['FactoryImages']))
  7.          //if(isset($_POST['FactoryImages']) && !empty ($_POST['FactoryImages']))
  8.          
  9.             $model->attributes = $_POST['FactoryImages'];
  10.            
  11.             //$photos = CUploadedFile::getInstancesByName('photos');
  12.             $photos = CUploadedFile::getInstancesByName('FactoryImages[image_name]');
  13.              
  14.             // proceed if the images have been set
  15.             if (isset($photos) && count($photos) > 0) {
  16.                 // go through each uploaded image
  17.                var_dump($photos);
  18.                 foreach ($photos as $image => $pic) {
  19.                     echo $pic->image_name.'<br />';
  20.                    
  21.                     if ($pic->saveAs(Yii::getPathOfAlias('webroot').'/images/'.$pic->image_name)) {
  22.                         // add it to the main model now
  23.                         $img_add = new FactoryImages();
  24.                         $img_add->filename = $pic->image_name; //it might be $img_add->name for you, filename is just what I chose to call it in my model
  25.                         $img_add->corporate_client  = $model->id; // this links your picture model to the main model (like your user, or profile model)
  26.                         $img_add->save(); // DONE
  27.                        
  28.                        
  29.                     }
  30.                     else{
  31.                         echo 'Cannot upload!';
  32.                     }
  33.                 }
  34.             }
  35.       // if ($model->save())
  36.                // $this->redirect(array('update', 'id' => $model->id));
  37.        
  38.         $this->render('create_test', array(
  39.             'model' => $model,
  40.  
  41.         ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement