本文整理汇总了PHP中app\models\File::defineType方法的典型用法代码示例。如果您正苦于以下问题:PHP File::defineType方法的具体用法?PHP File::defineType怎么用?PHP File::defineType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\File
的用法示例。
在下文中一共展示了File::defineType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionUpload
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;
}