简体   繁体   中英

How to save audio file from flash app to server using php?

My problem is save the audio file (.wav) that my flash application generate when the user finish record your voice.

I use, for this, the follow link: http://active.tutsplus.com/tutorials/actionscript/create-a-useful-audio-recorder-app-in-actionscript-3/

But this only save the audio for the client. I need to change this for save on the server.

Part of the code is (in MAIN.AS):

private function recordComplete(e:Event):void{
    fileReference.save(recorder.output, "recording.wav");
}

Where the first argument (recorder.output) is my file and the second argument is the name of my file.

I change this method for this:

private function recordComplete(e:Event):void{
  var urlReq:URLRequest = new URLRequest("extract_voice.php");
  urlReq.method = URLRequestMethod.POST;
  urlReq.contentType = "application/octet-stream";
  //var urlVars = new URLVariables();
  //urlVars.fileAudio = recorder.output;
  urlReq.data = recorder.output;
  //var loader:URLLoader = new URLLoader(urlReq);
  //loader.dataFormat = URLLoaderDataFormat.VARIABLES;
  loader.load(urlReq);
}

And my extract_voice.php is:

$recorder = file_get_contents('php://input');
$name = basename($recorder);
$status = move_uploaded_file($recorder, 'http://localhost/recording/audiofiles/' . $name);
if($status){
  echo 'WORK';
}

But when stop the recording, always show me the popup for save the file on my machine. (client).But not in the server.

Anyone can say me what I need to do? or if exist any other solution? (Like a RED5 but this doesn't work for me)

$recorder = file_get_contents('php://input');

$recorder variable holds binary data fetched from php input, not uploaded file. Instead of

$name = basename($recorder);
$status = move_uploaded_file($recorder, 'http://localhost/recording/audiofiles/' . $name);

use:

$name = md5($recorder).'.wav';
$status = file_put_contents('recording/audiofiles/'.$name, $recorder);

Note, that path to the file must be writable to web server, and it must be local path, not some web address.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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