因此,在我的項目中,用戶可以記錄自己,然後從我正在使用的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)將返回假但爲什麼我不知道。有人可以幫忙嗎?
謝謝!
順便說一句我跟着這個教程:http://net.tutsplus.com/tutorials/javascript-ajax/how-to-upload-files-with -codeigniter-and-ajax/ – Kat