Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. <?php
  2. class UploadController extends Controller{    
  3.     function actionIndex(){
  4.         $currentUser = User::model()->findByPk(Yii::app()->user->id);
  5.         $company = $currentUser->company;
  6.         $files = $company->files;
  7.         $dir = Yii::getPathOfAlias('application.uploads');
  8.       //  $dir = $mainUploadDir . '\company_1000'. echo $company->id;
  9.         $uploaded = false;
  10.         $model = new Upload();
  11.         if (isset($_POST['Upload'])){
  12.             $model->attributes = $_POST['Upload'];
  13.             $file = CUploadedFile::getInstance($model, 'file');
  14.             //$model->author = $currentUser->name;
  15.             $model->company_id = $company;
  16.             $model->originalName = $file->getName();
  17.             $model->uniqName = rand('1', time());
  18.             $model->author = $currentUser->name;
  19.             $model->company_id = $company;
  20.          
  21.          $model->downloadPath = 'www.planster.org/uploads/'. 'compnay_'. "echo $company_id" . "/" . $model->uniqName;        
  22.             if ($model->save()) {
  23.                 $uploaded = $file->saveAs($dir . '/' . $model->uniqName);
  24.                 //$model->uploadTime = new CDbExpression('NOW()');
  25.                 //Yii::app()->user->setFlash('success','Загрузка успешно завершена!');
  26.                 //$this->refresh();
  27.             }
  28.         }
  29.         $this->render('index',  array(
  30.                                     'model'=>$model,
  31.                                     'uploaded' => $uploaded,
  32.                                     'dir' => $dir,
  33.                                     'files' => $files,
  34.                                 ));
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement