阅读 591

uniapp实现通话录音实时上传、后端php-安卓手机





//php代码


public function uploadluyin(Request $request){


        if(empty($_FILES)){
            \Log::info(upload_luyin,[没有录音文件]);
            return ;
        }



        $file = $_FILES[upfile];
        $file_name = $file[name];
        $username = $_POST[username];
        $app_phone = $_POST[phone];
        $luyin_info = explode( , $file_name);

        $luyin_phone = $luyin_info[0];



        $save_file_name = implode(-,$luyin_info);

        $file_type = audio/mp3;
        if($file["type"] == $file_type) {

            $destinationPath = public_path(uploads/luyin_dir/);
            $time = time();
            $filePath = $destinationPath . $time . - . $save_file_name;
            $bool = move_uploaded_file($file["tmp_name"], $filePath);//将临时地址移动到指定地址

            if ($bool) {
                \Log::info(upload_luyin,[业务员:【.$username.--.$app_phone.】与客户:.$luyin_phone.通话文件上传成功]);

            } else {
                \Log::info(upload_luyin,[业务员:【.$username.--.$app_phone.】与客户:.$luyin_phone.通话文件上传失败]);
                $res = array(code => -1, msg => 上传失败);
                return json_encode($res);
            }
            $fileUrl = uploads/luyin_dir/ . $time . - . $save_file_name;


            $getID3 = new getID3;

            $ThisFileInfo = $getID3->analyze($fileUrl);

            $fileduration = $ThisFileInfo[playtime_seconds]; //这个获得的便是音频文件的时长
            $seconds = ceil($fileduration);  //

            $shichang = $this->secondTime($seconds);


            $LuyinModel = new Luyin();
            $params = array(
                app_phone => $app_phone,
                luyin_phone => $luyin_phone,
                username => $username,
                seconds => $seconds,
                shichang => $shichang,
                add_time => time(),
                file_path => http://.$_SERVER[HTTP_HOST] . / . $fileUrl

            );
            $id = $LuyinModel->addLuyin($params);

            if ($id) {
               \Log::info(upload_luyin,[业务员:【.$username.--.$app_phone.】与客户:【.$luyin_phone.】通话入库成功:.$id]);
                $res = array(code => 1, msg => 上传失败);
               return json_encode($res);

            } else {
               \Log::info(upload_luyin,[业务员:【.$username.--.$app_phone.】与客户:.$luyin_phone.通话入库失败]);
                $res = array(code => -1, msg => 上传失败);
                return json_encode($res);
            }


        }



    }

 

原文:https://www.cnblogs.com/wt645631686/p/14827477.html

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐