Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $model =new FactoryImages;
- // Uncomment the following line if AJAX validation is needed
- $this->performAjaxValidation($model);
- $type = isset($_GET['type']) ? $_GET['type'] : 'post';
- if(isset($_POST['FactoryImages']))
- //if(isset($_POST['FactoryImages']) && !empty ($_POST['FactoryImages']))
- $model->attributes = $_POST['FactoryImages'];
- //$photos = CUploadedFile::getInstancesByName('photos');
- $photos = CUploadedFile::getInstancesByName('FactoryImages[image_name]');
- // proceed if the images have been set
- if (isset($photos) && count($photos) > 0) {
- // go through each uploaded image
- var_dump($photos);
- foreach ($photos as $image => $pic) {
- echo $pic->image_name.'<br />';
- if ($pic->saveAs(Yii::getPathOfAlias('webroot').'/images/'.$pic->image_name)) {
- // add it to the main model now
- $img_add = new FactoryImages();
- $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
- $img_add->corporate_client = $model->id; // this links your picture model to the main model (like your user, or profile model)
- $img_add->save(); // DONE
- }
- else{
- echo 'Cannot upload!';
- }
- }
- }
- // if ($model->save())
- // $this->redirect(array('update', 'id' => $model->id));
- $this->render('create_test', array(
- 'model' => $model,
- ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement