Я вызываю php файл из javascript кода в Django, кажется, он не может его найти. Поэтому я подумал вызвать функцию python, которая будет выполнять ту же операцию, что и указанная в PHP.
коде js, где я вызываю php file
var filename = new Date().toISOString();
//filename to send to server without extension
//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
Загрузка. php
print_r($_FILES);
//this will print out the received name, temp name, type, size, etc.
$input = $_FILES['audio_data']['tmp_name']; //get the 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)
так что в основном этот php файл устанавливает файл BLOB на моем сервере
Может кто-нибудь, пожалуйста, помогите мне преобразовать этот php в python или даже выполнение той же операции с помощью ajax или некоторые из них тоже будут работать