2011-09-02 80 views
1
I believe I have most everything correctly configured for the recorder because I can 
1 - Get the Flash permission prompt 
2 - Start recording 
3 - Listen to the playback 
but when I go to save the file I can find it neither in the upload directory nor the temp dir. 

I know php is working because I have tested a post - upload form successfully. 

Here's the html and php: 


    <!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
<head> 
<title>My Recorder</title> 
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js'></script> 
<script type="text/javascript" src="js/swfobject.js"></script> 
<script type="text/javascript" src="js/recorder.js"></script> 

<script type="text/javascript"> 
$(function() { 
    var appWidth = 24; 
    var appHeight = 24; 
    var flashvars = {'event_handler': 'microphone_recorder_events', 'upload_image': 'images/upload.png'}; 
    var params = {}; 
    var attributes = {'id': "recorderApp", 'name': "recorderApp"}; 
    swfobject.embedSWF("recorder.swf", "flashcontent", appWidth, appHeight, "10.1.0", "", flashvars, params, attributes); 
}); 
</script> 

<style> 
#control_panel { white-space: nowrap; } 
#control_panel a { outline: none; display: inline-block; width: 24px; height: 24px; } 
#control_panel a img { border: 0; } 
#save_button { position: absolute; padding: 0; margin: 0; } 
#play_button { display: inline-block; } 
</style> 
</head> 

<body> 

    <div id="status"> 
    Recorder Status... 
    </div> 

    <div id="control_panel"> 
    <a id="record_button" onclick="Recorder.record('audio', 'audio.wav');" href="javascript:void(0);" title="Record"><img src="images/record.png" width="24" height="24" alt="Record"/></a> 
    <span id="save_button"> 
    <span id="flashcontent"> 
     <p>JavaScript enabled and Adobe Flash Player installed, please</p> 
    </span> 
    </span> 
    <a id="play_button" style="display:none;" onclick="Recorder.playBack('audio');" href="javascript:void(0);" title="Play"><img src="images/play.png" width="24" height="24" alt="Play"/></a> 
    </div> 

    <div id="upload_status"> 
    </div> 

    <form id="uploadForm" name="uploadForm"> 
    <input name="authenticity_token" value="xxxxx" type="hidden"> 
    <input name="upload_file[parent_id]" value="1" type="hidden"> 
    <input name="format" value="json" type="hidden"> 
    </form> 

</body> 
</html> 
<?php 
$save_folder = dirname(__FILE__) . "/audio"; 
if(! file_exists($save_folder)) { 
    if(! mkdir($save_folder)) { 
    die("failed to create save folder $save_folder"); 
    } 
} 

function valid_wav_file($file) { 
    $handle = fopen($file, 'r'); 
    $header = fread($handle, 4); 
    list($chunk_size) = array_values(unpack('V', fread($handle, 4))); 
    $format = fread($handle, 4); 
    fclose($handle); 
    return $header == 'RIFF' && $format == 'WAVE' && $chunk_size == (filesize($file) - 8); 
} 

$key = 'filename'; 
$tmp_name = $_FILES["upload_file"]["tmp_name"][$key]; 
$upload_name = $_FILES["upload_file"]["name"][$key]; 
$type = $_FILES["upload_file"]["type"][$key]; 
$filename = "$save_folder/$upload_name"; 
$saved = 0; 
if($type == 'audio/x-wav' && preg_match('/^[a-zA-Z0-9_\-]+\.wav$/', $upload_name) && valid_wav_file($tmp_name)) { 
    $saved = move_uploaded_file($tmp_name, $filename) ? 1 : 0; 
} 

if($_POST['format'] == 'json') { 
    header('Content-type: application/json'); 
    print "{\"saved\":$saved}"; 
} else { 
    print $saved ? "Saved" : 'Not saved'; 
} 

exit; 
?> 

btw - this came straight from the cykod site, I've done barely anything to it... 
also, how do i convert to mp3 upon pressing the save button? 
Thanks! 

回答

1

不知道你是否有過這個答案,但檢查你的文件夾權限。設置我的「音頻」文件夾後,每個人都可以讀/寫它的工作。當然,這不是最好的方法 - 你需要設置你的apache/php帳戶可寫入文件夾 - 但至少這應該讓你去。