chat room, send audio to store in server

nitiphone2021

New member
According to I make a website for chat and I want to send voice to communicate.

so I use this script from https://blog.addpipe.com/using-recorder-js-to-capture-wav-audio-in-your-html5-web-site/

This is javascript

Code:
function createDownloadLink(blob) {


	//name of .wav file to use during upload and download (without extendion)
	var filename = new Date().toISOString();

		console.log('bob = ' + typeof(blob));
		console.log('file name = ' + typeof(filename));
		  var fd=new FormData();
		  fd.append("audio_data",blob, filename);

		  $.ajax({

			url: "../func/upload.php",
			method: "POST",
			processData: false,
			contentType: false,
			data: fd,
			enctype: 'multipart/form-data',
			success: function (data) {
				console.log('SUCCESS' + data);

			},
			error: function (err) {
			}

		});


}

and this is server side PHP

Code:
<?php

//this will print out the received name, temp name, type, size, etc. 
print_r($_FILES);
$input = str_replace(":","_",$_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);

?>

This is the print output

Code:
Array
(
    [audio_data] => Array
        (
            [name] => 2021-07-02T07:59:33.877Z
            [type] => audio/wav
            [tmp_name] => C:\xampp\tmp\phpF3C8.tmp
            [error] => 0
            [size] => 44
        )

)
It seem no any error but I don't find any file on the server.

Could you please kindly help me check?
 
Now I can create the file but the the file is empty or no any soude data
Code:
//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 = "../management/design/voices/" . time() . uniqid() .".wav"; //letting the client control the filename is a rather bad idea 
//move the file from temp name to local folder using $output name 
$result = move_uploaded_file($input, $output);
 
Back
Top