美文网首页
TP 5.1 利用getid3 获取mp4、mp3时长等信息

TP 5.1 利用getid3 获取mp4、mp3时长等信息

作者: 小果酱_嗷嗷嗷 | 来源:发表于2019-07-05 10:20 被阅读0次

1.getid3 下载网址:https://www.getid3.org/ 
2.下载完成 解压是这样的目录 把getid3 弄到tp 项目中  extend 文件夹中

3.在application文件夹中找到common.php

4.先require 该文件 
require '../extend/getid3/getid3.php'; 然后添加该方法

/**

* @description 获取音视频时长

* JAM

* @param {File}文件

* @param {String}要取的信息名 playtime_string 为时长

*/

function get_file_size($file,$type ='playtime_string'){

    $fileName = ".".$file;

    if(file_exists($fileName)) {

        $mp3 = new getID3(); 

        $info =  $mp3->analyze($fileName); 

        //print_r($info);

      return $info[$type];

    }

}

5. 调用  
//获取文件对象

  $file = $this->request->file('file');

  //验证并上传

  $size = 1024*1024*50;

  $info = $file->validate(['size'=> $size,'ext'=>'mp4,mp3'])

      ->move('xxx/xxx/xxxxx');

  //判断是否成功

  if($info){

      $data['src'] = '/xxxx/xxxx/xxxx/'.$info->getSaveName();

      $data['playtime_string'] = get_file_size($data['src']);

      // print_r($res);

      $this->result($data,0,'上传成功');

  }else{

      $this->result('',200,$file->getError());

  }

                                                                                                                                                by 笔芯的小果酱

相关文章

网友评论

      本文标题:TP 5.1 利用getid3 获取mp4、mp3时长等信息

      本文链接:https://www.haomeiwen.com/subject/gacshctx.html