A complete exemple:
controller (I just print_r or echo variables for the javscript console)
PHP Code:
<?php
class Test extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('url_helper');
}
public function index() {
$this->load->library('form_validation');
$this->form_validation->set_rules('name','nom','required');
if ($this->form_validation->run() === FALSE) {
$this->load->view('upload');
} else {
if (!empty($_FILES)){
print_r($_FILES);
} else {
echo '$_FILES is empty';
}
}
}
}
The view upload
PHP Code:
<html>
<head>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/dropzone.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/newjavascript.js" /></script>
<link rel="stylesheet" href="https://rawgit.com/enyo/dropzone/master/dist/dropzone.css">
</head>
<body>
<form action="<?php echo site_url().'/test/index'; ?>" enctype="multipart/form-data" method="post" class="dropzone" id="property-form">
<div class="dropzone-preview">
</div>
<input type="text" name="name">
<button type="submit" value="OK"></button>
</form>
</body>
</html>
the good javascript (newjavascript):
Code:
Dropzone.options.propertyForm = {
maxFiles:11,
autoProcessQueue: false,
uploadMultiple: true,
acceptedFiles: "image/*",
maxFilesize: 1,
parallelUploads: 11,
init: function () {
var myDropzone = this;
this.element.querySelector("button[type=submit]").addEventListener("click", function(e) {
console.log('Click');
e.preventDefault();
e.stopPropagation();
myDropzone.processQueue();
});
// Listen to the sendingmultiple event. In this case, it's the sendingmultiple event instead
// of the sending event because uploadMultiple is set to true.
this.on("sendingmultiple", function() {
console.log('send event');
});
this.on("successmultiple", function(files, response) {
console.log(response);
});
this.on("errormultiple", function(files, response) {
console.log('error');
});
}
}
the response in my console:
send event newjavascript.js:22:15
Array
(
[file] => Array
(
[name] => Array
(
[0] => mcd.png
)
[type] => Array
(
[0] => image/png
)
[tmp_name] => Array
(
[0] => /tmp/php1B29UX
)
[error] => Array
(
[0] => 0
)
[size] => Array
(
[0] => 12549
)
)
)
evrything works