php - how to save uploaded image twice at two dirs in yii? -


i want assign file field input 2 variables, , want save 2 variables 2 different dirs, here code:

controller:

if(isset($_post['articles']))         {             $model->attributes=$_post['articles'];                         $model->date = date('y-m-d h:i:s');                         $model->display = 1;                         $model->visits = 0;                         $model->image = cuploadedfile::getinstance($model, 'image');                         $model->thumbnail = cuploadedfile::getinstance($model, 'image');             if($model->save()){                              if(!empty($model->image)){                                  $model->image->saveas(getcwd()."/images/articles/".$model->image);                                 if(!empty($model->thumbnail))                                 if(!$model->thumbnail->saveas(getcwd()."\images\articles\thumbnails/".$model->thumbnail))                                 $thumbnail = yii::app()->image->load(getcwd()."/images/articles/thumbnails/".$model->thumbnail);                                 $thumbnail->resize(64, 64);                                 $thumbnail->save();                             }                              $this->redirect(array('view','id'=>$model->id));                         } 

after saving model, thumbnails dir still empty, , getting error image extension there no file loaded, how can save image twice in 2 dirs?

you don't need 2 instances of 2 images, default saveas deletes temp file, smthing this:

if(isset($_post['articles']))     {         $model->attributes=$_post['articles'];         $model->date = date('y-m-d h:i:s');         $model->display = 1;         $model->visits = 0;         $model->image = cuploadedfile::getinstance($model, 'image');         if($model->save()){             if(!empty($model->image)){                  $model->image->saveas(getcwd()."/images/articles/".$model->image,false);//here's trick                  if($model->image->saveas(getcwd()."\images\articles\thumbnails/".$model->image) {                        $thumbnail = yii::app()->image->load(getcwd()."/images/articles/thumbnails/".$model->image);                        $thumbnail->resize(64, 64);                        $thumbnail->save();                  }                   $this->redirect(array('view','id'=>$model->id));             } 

you without saving image, loading again - on fly, ex. euploadedimage.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -