我在我的 CI 项目中使用 Dropzone。但是,我无法管理它,我的文件也没有上传。它甚至不将图像名称传递给变量,因为它在插入数据库时给出了 NULL。
这是我的看法:
<div id="dropzone" class="dropzone"></div>
<script type="text/javascript">
Dropzone.autoDiscover = false;
var base_url = "<?php echo base_url();?>";
$("div#dropzone").dropzone({
url: base_url + 'cars/addpic',
addRemoveLinks: true,
uploadMultiple: true,
paramName: "files",
acceptedFiles: "image/*",
dictDefaultMessage: "<span class='mif-file-upload mif-3x'></span> <br>Faykkari sechin gorek"
});
</script>
这是我的控制器:
public function addpic() {
$config['upload_path'] = './assets/img/cars/';
$config['allowed_types'] = 'jpg|png|jpeg|JPG|PNG|JPEG';
$config['overwrite'] = FALSE;
$config['remove_spaces'] = TRUE;
$config['max_size'] = '25000';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if($this->upload->do_upload('files'))
{
//for multiple
$filesCount = count($_FILES['files']['name']);
for($i = 0; $i < $filesCount; $i++){
$_FILES['filee']['name'] = $_FILES['files']['name'][$i];
$_FILES['filee']['type'] = $_FILES['files']['type'][$i];
$_FILES['filee']['tmp_name'] = $_FILES['files']['tmp_name'][$i];
$_FILES['filee']['error'] = $_FILES['files']['error'][$i];
$_FILES['filee']['size'] = $_FILES['files']['size'][$i];
if(!$this->upload->do_upload('filee')){
$manyimages = '';
} else {
$fileData = $this->upload->data();
$manyimages[] = $fileData['file_name'];
}
}
$manymanyimages= implode(',', $manyimages);
}
然后我将这些数据传递给所有数据都上传到数据库的主函数。
public function create($manymanyimages) {
//some other stuff here
$data = array(
'photos' => $manymanyimages
);
$this->cars_model->add_car($data);
redirect('');
}