通过调整后的表格和dropzone和codeigniter上传图像

时间:2017-06-07 16:57:40

标签: image codeigniter upload

我试图通过dropzone / codeigniter上传图片。不幸的是,我没有将后期数据发送到控制器,然后发送到模态。显然它不是ajax我可以插入数据以获得它。

以下是表格的一部分:

<div class="dropzone" id="my-dropzone" name="mainFileUploader">
    <div class="fallback">
        <input name="file" type="file" multiple />
    </div>
</div>

这是脚本:

var myDropzone = new Dropzone("#my-dropzone", { 
    url: "<?=admin_url()?>invoice_items/upload_image",
    data: this,
    method: "post",
    addRemoveLinks:true,
    acceptedFiles: '.jpg,.jpeg,.JPEG,.JPG,.png,.PNG',

    init: function () {
        this.on("addedfile", function (file) {
            console.log(file);
        });
    }
});

这是控制器

public function upload_image(){
    if ($this->input->post()) {
        $this->invoice_items_model->add_image($this->input->post());
    }
}

这是模态

public function add_image($data){
    $dat = array(
        'rel_name' => $data['name'],
        'rel_type' => 'cms_items',
        'dateadded' => date('Y-m-d H:i:s')
    );
    $this->db->insert('tblfiles', $dat);
}

1 个答案:

答案 0 :(得分:0)

对于需要答案的人:

var myDropzone = new Dropzone("#my-dropzone", { 
    url: "<?=admin_url()?>invoice_items/upload_image",
    files: this,
    method: "post",
    addRemoveLinks:true,
    acceptedFiles: '.jpg,.jpeg,.JPEG,.JPG,.png,.PNG',
    init: function (data) {
        this.on("sucess",function(file, xhr, formData){

        });


    },
    dictDefaultMessage: "<?=_l('drop_files_here_to_upload')?>",
    dictRemoveFile : "<?=_l('remove_file')?>"
});