2012-12-08 37 views
0

因此,在我的項目中,用戶可以記錄自己,然後從我正在使用的recorderplugin中獲取blob文件。我試圖通過codeigniter中的fileupload ajax調用將該blob上傳到服務器,但我無法找到如何使其工作。使用ajax fileupload和codeignitert在服務器上保存blob

這是我的javascript代碼:(

recorder.exportWAV(function(blob) { 
    console.log(blob); 
     $.ajaxFileUpload({ 
       url : "../ajax/saverecording/", 
       secureuri  :false, 
       fileElementId  :"geenidee", 
       dataType : blob.type, 
       data: blob.data, 
       success: function(data, status) { 
        if(data.status != 'error') 
         alert("hoera!"); 
        alert(data.msg); 
       } 
      }); 
     }); 

這是ajax.php控制器我saverecording功能

public function saverecording() 
{ 
    $status = ""; 
    $msg = ""; 
    $file_element_name = 'komaan'; 
    if ($status != "error") 
    { 
      $config['upload_path'] = '../../upload/audio/recordings/'; 
      $config['allowed_types'] = 'wav'; 
      $this->load->library('upload', $config); 
      if (!$this->upload->do_upload($file_element_name)) 
      { 
      $status = 'error'; 
      $msg = $this->upload->display_errors('', ''); 
      echo 'alert("this is not working!");'; 
      } 
      else 
      { 
      $data = $this->upload->data(); 
      } 
      @unlink($_FILES[$file_element_name]); 
     } 
} 

$這個 - > upload-> do_upload($ file_element_name)將返回假但爲什麼我不知道。有人可以幫忙嗎?

謝謝!

+0

順便說一句我跟着這個教程:http://net.tutsplus.com/tutorials/javascript-ajax/how-to-upload-files-with -codeigniter-and-ajax/ – Kat

回答

0

你可以不修改文件輸入,但你可以用AJAX上傳:

recorder.exportWAV(function(blob) { 
    $.ajax("something.php", { 
     data: blob, 
     processData: false, 
     contentType: false, 
     method: "POST", 
     success: function() { 

     } 
    }); 
}); 
+0

感謝這給了我一個正確的方向(我認爲)一個新的推動,但我再次卡住了。我改變了我的問題到我現在的位置。 – Kat

相關問題