JSON_enconde在文件编码上返回null

时间:2018-04-01 15:38:03

标签: javascript php ajax file-upload

我正在尝试使用PHP和JavaScript操纵上传的歌曲。要连接这两个,我正在使用AJAX。

HTML

<form enctype="multipart/form-data" method="POST" action="fileUpload.php" id="uploadForm">
  <input type="hidden" name="Max_Size" value="2048">
  <input type="file" name="uploadedSong" accept=".mp3"><br>
  <button type="submit">Submit</button>
</form>

JS:

formSongUpload.addEventListener('submit', function(){
  let requisition = new XMLHttpRequest();
  requisition.onreadystatechange = manipulateThisSong(//Uploaded Song Goes Here);
  requisition.responseType = 'json';
  requisition.open('POST', 'fileUpload.php');
  requisition.send();
  //Temporary alert
  alert(requisition.response);
})

PHP:

<?php
  $file = $_FILES['uploadedSong']['name'];
  //Not verifying the file size here, just trying to send the upload
  echo(json_encode($file));
?>

但是,回复正在接收null。为什么会发生这种情况,我该如何解决?

0 个答案:

没有答案