javascript - 在服务器上保存音频文件特定文件夹
问题描述
我一直在使用以下示例-> https://blog.addpipe.com/using-recorder-js-to-capture-wav-audio-in-your-html5-web-site/
我对此进行了很多自定义,但是当我到达上传到服务器的部分时,它不会上传任何内容。
Upload.php(自定义文件)
if (isset($_FILES['audio_data'])) {
$fileName = "audio";
if(empty($_SESSION['foldername'])){
$_SESSION['foldername'] = $_SERVER['DOCUMENT_ROOT']."/data/".$_SESSION['username'];
}
$uploadDirectory = $_SESSION['foldername'].'/'.$fileName;
if (!move_uploaded_file($_FILES['audio_data']["tmp_name"], $uploadDirectory)) {
echo(" problem moving uploaded file");
}
echo($uploadDirectory);
}
它创建下载链接的部分,以及上传链接的部分(上面示例中的标准)
function createDownloadLink(blob) {
var url = URL.createObjectURL(blob);
var au = document.createElement('audio');
var li = document.createElement('li');
var link = document.createElement('a');
//name of .wav file to use during upload and download (without extension)
var filename = new Date().toISOString();
//add controls to the <audio> element
au.controls = true;
au.src = url;
//save to disk link
link.href = url;
link.download = filename+".wav"; //download forces the browser to donwload the file using the filename
link.innerHTML = "Save to disk";
//add the new audio element to li
li.appendChild(au);
//add the filename to the li
li.appendChild(document.createTextNode(filename+".wav "))
//add the save to disk link to li
li.appendChild(link);
//upload link
var upload = document.createElement('a');
upload.href="#";
upload.innerHTML = "Upload";
upload.addEventListener("click", function(event){
var xhr=new XMLHttpRequest();
xhr.onload=function(e) {
if(this.readyState === 4) {
console.log("Server returned: ",e.target.responseText);
}
};
var fd=new FormData();
fd.append("audio_data",blob, filename);
xhr.open("POST","upload.php",true);
xhr.send(fd);
})
li.appendChild(document.createTextNode (" "))//add a space in between
li.appendChild(upload)//add the upload link to li
//add the li element to the ol
recordingsList.appendChild(li);
}
控制台上的答案是 Server returned: ""
在这里:服务器返回:“,e.target.responseText。
解决方案
我打开服务器上的错误,发现是服务器配置错误。
max_upload_size max_execution_time post_max_size
推荐阅读
- java - 如何从 Python 服务器向 Java 客户端发送消息
- python - 如何匹配引号之间的字符串中的确切字符串
- kendo-grid - 如何在剑道网格中以编程方式添加组和组的总和
- javascript - 如何使用 express 和 mongoose 连接到本地网络中的 MongoDB
- css - 给出开门效果然后跳转到下一页
- html - 如何让用户只选择整张照片的特定部分
- java - 我的模拟器没有运行。Logcat 中甚至没有显示任何内容。它显示“No Connected device”和“No Debuggable pro”
- wordpress - 如何避免在 sitemap.xml 中索引或索引规范 url
- angular - Type '{ key: string; }' is not assignable to type 'Product' Angular 7
- autoit - AutoIt中如何对二维数组的列序列进行排序