Exemplo n.º 1
0
 public function getFiles()
 {
     return $this->hasMany(SaleFiles::className(), ['sale_id' => 'id']);
 }
Exemplo n.º 2
0
 public function actionUploadFile()
 {
     if (Yii::$app->request->isPost) {
         $id = Yii::$app->request->post('sale_id');
         $path = Yii::$app->params['uploadSalePath'] . DIRECTORY_SEPARATOR . $id;
         BaseFileHelper::createDirectory($path);
         $file = UploadedFile::getInstanceByName('files');
         if (file_exists($path . DIRECTORY_SEPARATOR . $file->name)) {
             return false;
         }
         $model = new SaleFiles();
         $model->sale_id = $id;
         $model->name = $file->name;
         if ($model->save()) {
             if ($model->save()) {
                 if (!$file->saveAs($path . DIRECTORY_SEPARATOR . $model->name)) {
                     $model->delete();
                 }
             }
         }
         sleep(1);
         return true;
     }
     return false;
 }