我正在构建一个录音项目,我想通过blob将音频上传到文件夹(上传)。 这是我迄今取得的成就:
var url = URL.createObjectURL(blob);
var li = document.createElement('li');
var au = document.createElement('audio');
var hf = document.createElement('a');
au.controls = true;
au.src = url;
hf.href = url;
hf.download = 'audio_recording_' + new Date().getTime() + '.wav';
hf.innerHTML = hf.download;
li.appendChild(au);
li.appendChild(hf);
fileName=hf.download;
console.log(fileName);
var data = new FormData();
data.append(url, blob);
$.ajax({
url : "upload.php",
type: 'POST',
data: data,
contentType: false,
processData: false,
success: function(data) {
console.log(data);
}
});
这是ajax函数的php代码(upload.php):
<?php
$temp = explode(".", $_FILES["fileName"]["name"]);
$extension = end($temp);
$fileName=$_POST['fileName'];
if ($_FILES["fileName"]["error"] > 0) {
console.log( "Return Code: " . $_FILES["fileName"]["error"] . "<br>");
} else {
if (file_exists("upload/" . $_FILES["fileName"]["name"])) {
console.log( $_FILES["fileName"]["name"] . " already exists. ");
} else {
move_uploaded_file($_FILES["fileName"]["tmp_name"],
"upload/" . $_FILES["fileName"]["name"]);
}
}
?>
当在文件夹上传中未保存对音频的补偿并且获得以下错误时:未定义的索引:upload.php中的fileName 我的代码出了什么问题???请帮忙