簡體   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