繁体   English   中英

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

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

我的问题是保存用户完成录制您的声音时Flash应用程序生成的音频文件(.wav)。

为此,我使用以下链接: http : //active.tutsplus.com/tutorials/actionscript/create-a-useful-audio-recorder-app-in-actionscript-3/

但这只会为客户端保存音频。 我需要更改此值以保存在服务器上。

部分代码是(在MAIN.AS中):

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

第一个参数(recorder.output)是我的文件,第二个参数是我的文件名。

我为此更改此方法:

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);
}

我的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';
}

但是,当停止录制时,请始终向我显示将文件保存到计算机上的弹出窗口。 (客户端)。但不在服务器中。

谁能说我该怎么办? 或是否存在其他解决方案? (就像RED5,但这对我不起作用)

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

$recorder变量保存从php输入获取的二进制数据,而不是上传的文件。 代替

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

采用:

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

请注意,该文件的路径必须可写到Web服务器,并且它必须是本地路径,而不是某些网址。

暂无
暂无

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

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