I'm trying to manipulate a uploaded song using PHP and JavaScript. To connect the two, I'm using 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));
?>
However, the response is recieving null
. Why does this happen and how can I resolve it?