我的Products
控制器具有view
功能和processImages
功能。
processImages
函数收到的$ _FILES变量总是空的,我无法找出原因!
PS :processImages
函数末尾传递的'1'是产品ID,因此我可以在文件上传后创建关系。
我的view.ctp
视图是:
<form action="/project002/products/processImages/1" class="dropzone" id="my-awesome-dropzone" enctype="multipart/form-data" method="post" accept-charset="utf-8">
<input type="hidden" name="_method" value="PUT"/>
<input class="btn btn-primary" id="processImageUploads" type="submit" value="Upload"/>
</form>
<script>
Dropzone.autoDiscover = false;
$("#my-awesome-dropzone").dropzone({
paramName: "productImage",
maxFiles: <?php echo 16 - count($product['Image']);?>,
addRemoveLinks: true,
acceptedFiles: '.jpg,.jpeg,.png',
dictInvalidFileType: 'This file type is not supported.',
autoProcessQueue: false,
dictRemoveFile: 'Remove Image',
parallelUploads: 16,
uploadMultiple: true,
init: function() {
this.on("addedfile", function() {
if (this.files[<?php echo 15 - count($product['Image']);?>]!=null){
this.removeFile(this.files[0]);
$( "#count_left" ).html('Image upload limit reached!');
}
});
var myDropzone = this;
$("#processImageUploads").bind("click", function (e) {
e.preventDefault();
e.stopPropagation();
// If the user has selected at least one file, AJAX them over.
if (myDropzone.files.length !== 0) {
myDropzone.processQueue();
$('#my-awesome-dropzone').submit();
} else {
$('#my-awesome-dropzone').submit();
}
});
myDropzone.on("complete", function(file) {
myDropzone.removeFile(file);
});
}
});
</script>