public function actionUpload()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $result = [];
     $files = UploadedFile::getInstances(new File(), 'uploadedFiles');
     foreach ($files as $index => $file) {
         $model = new File();
         $model->uploadedFiles = [$file];
         $model->user_id = Yii::$app->user->id;
         $model->storage = File::STORAGE_OS;
         $model->extension = $file->extension;
         $model->type = File::defineType($model->extension);
         if ($model->upload()) {
             $item = ['id' => $model->id, 'url' => $model->getUrl(), 'type' => $model->getMimeType()];
             if ($releaseId = Yii::$app->request->get('rid')) {
                 $release = Release::findOne($releaseId);
                 if ($release && $release->artist->user_id == Yii::$app->user->id) {
                     if ($model->type == $model::TYPE_IMAGE) {
                         $cover = new Cover(['release_id' => $release->id, 'file_id' => $model->id, 'is_main' => false]);
                         $cover->save();
                         $item['image_id'] = $cover->id;
                     } elseif ($model->type == $model::TYPE_AUDIO) {
                         $track = new Track(['release_id' => $release->id, 'original_name' => $file->baseName, 'number' => $release->getTracks()->count() + 1, 'file_id' => $model->id]);
                         $track->save();
                         $item['track_id'] = $track->id;
                         $item['comname'] = $track->getComname();
                         $item['number'] = $track->number;
                     }
                 }
             }
             if ($artistId = Yii::$app->request->get('aid')) {
                 $photo = new Photo(['artist_id' => (string) $artistId, 'file_id' => $model->id, 'is_main' => false]);
                 $artist = Artist::findOne($artistId);
                 if ($artist && $artist->user_id == Yii::$app->user->id) {
                     $photo->save();
                     $item['image_id'] = $photo->id;
                 }
             }
             //                if ($model->type == $model::TYPE_AUDIO) {
             //                    $getID3 = new getID3();
             //                    $tags = $getID3->analyze($model->getPath(true))['tags']['id3v2'];
             //                    $item['meta'] = [
             //                        'title' => $tags['title'][0],
             //                        'number' => explode('/', $tags['track_number'][0])[0],
             //                        'disc' => explode('/', $tags['part_of_a_set'][0])[0],
             //                        'lyric' => $tags['unsynchronised_lyric'][0],
             //                        'info' => $tags['comment'][0],
             //                    ];
             //                }
             if ($model->type == $model::TYPE_AUDIO) {
                 $item['meta'] = ['title' => $file->baseName, 'number' => $index + 1, 'disc' => '', 'lyric' => '', 'info' => ''];
             }
             $result[] = $item;
         }
     }
     return $result;
 }
 /**
  * Creates a new Track model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Track();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }