简体   繁体   English

如何使用PHP将音频文件从Flash应用保存到服务器?

[英]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. 我的问题是保存用户完成录制您的声音时Flash应用程序生成的音频文件(.wav)。

I use, for this, the follow link: http://active.tutsplus.com/tutorials/actionscript/create-a-useful-audio-recorder-app-in-actionscript-3/ 为此,我使用以下链接: 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): 部分代码是(在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. 第一个参数(recorder.output)是我的文件,第二个参数是我的文件名。

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: 我的extract_voice.php是:

$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) (就像RED5,但这对我不起作用)

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

$recorder variable holds binary data fetched from php input, not uploaded file. $recorder变量保存从php输入获取的二进制数据,而不是上传的文件。 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. 请注意,该文件的路径必须可写到Web服务器,并且它必须是本地路径,而不是某些网址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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