Example #1
0
 /**
  * Uploads a new models.
  */
 public function actionUpload()
 {
     // Get the session Id passed from SWFUpload. We have to do this to work-around the Flash Player Cookie Bug
     if (isset($_POST['PHPSESSID'])) {
         session_id($_POST['PHPSESSID']);
     }
     // Check the upload
     if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name']) || $_FILES['Filedata']['error'] != 0) {
         exit(0);
     }
     if (file_exists(Yii::app()->params['filePath'] . $_FILES['Filedata']['name'])) {
         $_FILES['Filedata']['name'] = File::getNonExistName(Yii::app()->params['filePath'] . $_FILES['Filedata']['name']);
     }
     if (@(!move_uploaded_file($_FILES['Filedata']['tmp_name'], Yii::app()->params['filePath'] . $_FILES['Filedata']['name']))) {
         exit(0);
     }
     $model = new File();
     $model->name = $_FILES['Filedata']['name'];
     $f = escapeshellarg(Yii::app()->params['filePath'] . $_FILES['Filedata']['name']);
     $model->type = trim(`file -bi {$f}`);
     $model->createTime = time();
     $model->save();
     echo $this->renderPartial('_create', array('model' => $model));
 }