jQuery-File-Upload不会返回$ _FILES

时间:2014-12-27 13:58:57

标签: javascript php jquery codeigniter file-upload

我正在使用blueimp的jQuery文件上传来上传文件,我想编写自己的处理程序,但是,由于某种原因,它不会上传文件。我使用CodeIgniter作为框架。

我想检查文件是否上传,但$ _FILES(console.log(data.result);)给出[]而不是缓存文件。我正在开发一个localhost环境。

我的HTML

<form action="{{ base_url() }}ajax/update_client_status" method="post" enctype="multipart/form-data">
    <div class="form-group inline m-b-none">
        <input type="file" data-type="process" class="filestyle" multiple="false" data-icon="false" data-classButton="btn btn-default" data-classInput="form-control v-middle inline input-s-lg" data-buttonText="Kies Excel" <!--accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"-->                        
    </div>
    <div id="progress" class="pull-right animated" style="display:none;">
        <small class="text-muted inline m-r-sm"><em></em></small>
        <div class="progress progress-sm progress-s-sm m-t-sm m-b-none inline">
            <div class="progress-bar bg-success"></div>
        </div> 
    </div>
</form>

js

$(function(){   

    $('input:file[data-type=process]')
        .fileupload({
            add: function (e, data) { 
                if (data.autoUpload || (data.autoUpload !== false && $(this).fileupload('option', 'autoUpload'))) {
                    $('#progress')
                        .show()
                        .addClass('fadeIn')
                        .find('em').text('Uploaden');
                    data.process().done(function () {
                        data.submit();
                    });
                }
            },
            progress: function (e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
                $('#progress .progress-bar').css( 'width', progress + '%');
            },
            done: function (e, data) {
                console.log( data.result );
            }
        });

});    

最后是CI控制器

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Ajax extends CI_Controller {
public function __construct()
{
    parent::__construct();
}

public function _remap( $method )
{
    if( !$this->input->is_ajax_request() ) {
        show_404(); // redirect to the 404 if ajax wasn't used for this request
    } else {
        $this->$method(); // continue the method
    }
}

public function update_client_status()
{
    $response = $_FILES;
    $this->output->set_content_type('application/json')->set_output( json_encode( $response ) );
}
}

0 个答案:

没有答案