【问题标题】:How to save audio file from flash app to server using php?如何使用 php 将音频文件从 Flash 应用程序保存到服务器?
【发布时间】:2012-10-16 07:57:13
【问题描述】:

我的问题是保存我的 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,但这对我不起作用)

【问题讨论】:

    标签: php flash audio-recording


    【解决方案1】:

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

    注意,该文件的路径必须对网络服务器是可写的,并且必须是本地路径,而不是某个网址。

    【讨论】:

    • 我正在为变量 $recorder 做 print_r 并且是空的。
    • 我真的认为下面的代码: $recorder = file_get_contents('php://input');不工作,或者在 MAIN.AS 中不要将文件 wav 发送到我的 php 脚本。
    猜你喜欢
    • 2011-05-25
    • 1970-01-01
    • 2012-10-30
    • 2017-01-11
    • 2015-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-20
    相关资源
    最近更新 更多