예제 #1
0
    public function addDropboxFiles($uploadsession)
    {
        $files = $this->tmpFiles;
        $existFiles = count($this->images);
        $availableFiles = $this->maxFiles - $existFiles;
        $cnt = 0;
        if($files){

            if(Yii::app()->session->itemAt($uploadsession)){

                $folder='uploads'. DIRECTORY_SEPARATOR .'tmp'. DIRECTORY_SEPARATOR;

                $dataSession = Yii::app()->session->itemAt($uploadsession);
                

                foreach($files as $fileUploadName){

                    if(is_array($dataSession)){
                        foreach($dataSession as $key => $value){
                            if($fileUploadName == $key){
                                if(file_exists($folder.$value )) {

                                	if($cnt >= $availableFiles)	
                                		break 2;

                                    $file = $folder.$value;
                                    $ext = pathinfo($folder.$value, PATHINFO_EXTENSION);

                                    $base = md5(rand(1000,4000));
                                    $unique = $base.'_obj';
                                    $suffix = 1;

                                    while (file_exists($this->getFileFolder() . $unique . $ext)){
                                        $unique = $base.'_'.$suffix;
                                        $suffix++;
                                    }
                                    $filename =  $unique . '.' . $ext;
                                    $fullPath = $this->getFileFolder() . $filename;
                                    
                                    if (copy($folder.$value, $fullPath)) {
                                        unlink($folder.$value);
                                        $image = new ObjectsImages();
                                        $image->object = $this->getPrimaryKey();
                                        $image->filename = $filename;
                                        $image->realname = $key;

                                        Yii::import('ext.phpthumb.PhpThumbFactory');
										$thumb  = PhpThumbFactory::create($fullPath);
										$thumb->setOptions(array('jpegQuality'=>100));
										$thumb->resize(1500)->save($fullPath);

                                        $image->save();
                                        $cnt++;
                                        	
                                    } else {
                                       // throw new CHttpException(404, Yii::t('Site', 'Cannot copy file to folder.'));
                                    }
                                    

                                }
                            break;
                            }
                        }
                    }

                    
                }
            }
            
        }
    }