blovekyo 发表于 2017-12-30 07:27:46

表单提交音乐文件(php)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">
  
<head>
  
<meta http-equiv="Content-Type" content="text/html; " />
  
<title>无标题文档</title>
  
</head>
  
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
  
<body>
  
<div>
  

  
<form action="shiyancl.php" method="post" enctype="multipart/form-data">
  
<input type="file"name="file"/>
  
<audio controls autoplay=""></audio>
  
<input type="submit" type="button" value="提交"/>
  
</form>
  

  
</div>
  
</body>
  
<script>
  
//录音上传
  
            $(function () {
  
$("#test").change(function () {
  
var objUrl = getObjectURL(this.files);
  
$("#audio").attr("src", objUrl);
  
$("#audio").pause();
  
$("#audio").show();
  
$("#mp3_submit").show()
  
getTime();
  

  
});
  
});
  
<!--获取mp3文件的时间 兼容浏览器-->
  
function getTime() {
  
setTimeout(function () {
  
var duration = $("#audio").duration;
  
if(isNaN(duration)){
  
getTime();
  
}
  
else{
  
console.info("该歌曲的总时间为:"+$("#audio").duration+"秒")
  
}
  
}, 10);
  
}
  
<!--把文件转换成可读URL-->
  
function getObjectURL(file) {
  
var url = null;
  
if (window.createObjectURL != undefined) { // basic
  
                  url = window.createObjectURL(file);
  
} else if (window.URL != undefined) { // mozilla(firefox)
  
                  url = window.URL.createObjectURL(file);
  
} else if (window.webkitURL != undefined) { // webkit or chrome
  
                  url = window.webkitURL.createObjectURL(file);
  
}
  
return url;
  

  
}
  
</script>
  
</html>
页: [1]
查看完整版本: 表单提交音乐文件(php)