2012-10-15 19 views
2

我的問題是保存我的Flash應用程序在用戶完成錄製語音時生成的音頻文件(.wav)。如何使用PHP將音頻文件從Flash應用程序保存到服務器?

我用的,對於這一點,以下網站: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但這不適用於我)

回答

0

$ 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服務器,而且它必須是本地路徑,而不是一些網址。

+0

我正在爲變量$記錄器做print_r並且是空的。 – user6964

+0

我真的認爲,下面的代碼:$ recorder = file_get_contents('php:// input'); 不要工作,或在MAIN.AS不要將文件wav發送到我的PHP腳本。 – user6964

相關問題