uniapp实现通话录音实时上传、后端php-安卓手机
class="content"> class="header"> "../../static/shilu-login/logo.png"> class="list"> class="list-call"> class="img" src="/static/shilu-login/1.png"> class="sl-input" v-model="phone" type="number" maxlength="11" placeholder="输入当前手机号" />class="list-call"> class="img" src="/static/shilu-login/4.png"> class="sl-input" v-model="username" type="text" maxlength="32" placeholder="输入您的姓名" username="true" />class="button-login" hover-class="button-hover" @tap="start"> 保存 class="list"> class="list-call"> 手机号:{{this.phone}} class="list-call"> 姓名:{{this.username}} class="list-call"> 手机型号:{{this.phone_model}} class="list-call"> 设备号:{{this.phone_uuid}}
//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