繁体   English   中英

警告 move_uploaded_file():无法在 php 中移动音频文件

[英]Warning move_uploaded_file(): Unable to move audio file in php

我有使用 Recorder.js 的简单 Record Wave 脚本

现在的问题是

  1. 记录正常
  2. 减少到我的记录没问题
  3. 从blob下载记录文件没问题
  4. 上传记录文件(这里是问题)
  5. 操作系统(Windows 10 和 appserv)

我的上传.php

    <?php
    print $_FILES["audio_data"]["tmp_name"]; //this will print out the received name, temp name, type, size, etc.
    //check if upload folder exist or not
    if(!is_dir("uploads")){
        $res = mkdir("uploads",0777); 
    }

    $size = $_FILES['audio_data']['size']; //the size in bytes
    $input = $_FILES['audio_data']['tmp_name']; //temporary name that PHP gave to the uploaded file
    $output = $_FILES['audio_data']['name'].".wav"; //letting the client control the filename is a rather bad idea
    //move the file from temp name to local folder using $output name
    move_uploaded_file($input, $output)

    ?>

我的js文件的一部分

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 extendion)
    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);
}

当单击上传 > 在控制台中获取该错误时

<b>Warning</b>:  move_uploaded_file(2019-12-05T17:30:46.190Z.wav): failed to open stream: Invalid argument in <b>F:\AppServ\www\audio\upload.php</b> on line <b>12</b><br />
<br />
<b>Warning</b>:  move_uploaded_file(): Unable to move 'C:\Windows\Temp\php891B.tmp' to '2019-12-05T17:30:46.190Z.wav' in <b>F:\AppServ\www\audio\upload.php</b> on line <b>12</b><br />

您使用输出目录作为文件名,因此会引发错误。

由于您的上传目录是uploads。

试着更新这个:

$output ="uploads/".$_FILES['audio_data']['name'].".wav";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM