首页 > 解决方案 > 在服务器上保存音频文件特定文件夹

问题描述

我一直在使用以下示例-> 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。

标签: javascriptphphtml

解决方案


我打开服务器上的错误,发现是服务器配置错误。

max_upload_size max_execution_time post_max_size


推荐阅读