使用dropzone无法发送超过4个文件

时间:2017-05-17 13:53:36

标签: javascript php file-upload dropzone.js

这很奇怪......

我可以使用dropzone发送0,1,2,3,4个文件,但不能发送5个或更多..

我想我在这里正确定义了选项:

source:{
 {
  title:"welcome page",
  link:"/home"
 },
 {
  title:"how it works",
  link:"/howitworks"
 },
...
}

我说得对,因为当我拖动超过6个文件时,我会看到错误消息:Dropzone.options.myDropzone = { url: "action.php", autoProcessQueue: false, uploadMultiple: true, parallelUploads: 6, maxFilesize: 5, maxFiles: 6, addRemoveLinks: true, paramName: 'userfile', acceptedFiles: 'image/*', dictMaxFilesExceeded: 'Too many files! Maximum is {{maxFiles}}', // The setting up of the dropzone init: function() { dzClosure = this; // Makes sure that 'this' is understood inside the functions below. // for Dropzone to process the queue (instead of default form behavior): document.getElementById("submit-form").addEventListener("click", function(e) { e.preventDefault(); e.stopPropagation(); // Make sure that the form isn't actually being sent. // If the user has selected at least one file, AJAX them over. if (dzClosure.files.length !== 0) { // dzClosure.options.autoProcessQueue = true; dzClosure.processQueue(); // Else just submit the form and move on. } else { $('#foorm').submit(); } }); // send all the form data along with the files: this.on("sendingmultiple", function(data, xhr, formData) { formData.append("name", $("#name").val()); formData.append("email", $("#email").val()); }); this.on("sucessmultiple", function(files, response) { // dzClosure.options.autoProcessQueue = false; $(location).attr('href', 'message_sent.html') }); } }

这个边界在源代码中是否有意义?

更多细节: 我的表格的简化版如下

Too many files! Maximum is 6

我的<form id="foorm" method="post" action="action.php" enctype="multipart/form-data"> <input type="text" id="name" name="name" required> <input type="email" id="email" name="email" required> <div class="dropzone" id="myDropzone"> <button type="submit" name="submit-form" id="submit-form">Send!</button> </form> 首先显示action.phpjson_encode($_FILES);

并且在发送少于4个文件时它们是预期的,并且在发送5个或更多文件时json_encode($_POST);

修改

如果尺寸较小,我可以上传5个或更多!除了dropzone上的bug之外,这可能是什么? (诚​​实的问题)

3 个答案:

答案 0 :(得分:1)

根据最近的评论,问题似乎是您受到PHP文件上传设置的限制。

upload_max_filesize中增加php.ini。默认值为&#34; 2M&#34; (2MB)。

您可能还需要增加post_max_size,其默认值为&#34; 8M&#34;。别忘了重启HTTP服务器。

http://php.net/manual/en/ini.core.php#ini.file-uploads

答案 1 :(得分:0)

试试这个,将autoProcessQueue设为true,将init设为this.on('addedfile', function(file) { if (this.files[10] != null) { this.removeFile(this.files[0]); } }); this.on('maxfilesreached', function(file) { if (this.files[10] != null) { this.removeFile(this.files[0]); } });

将以下事件添加到Dropzone.options.myDropzone = { url: "action.php", autoProcessQueue: true, uploadMultiple: false, parallelUploads: 10, maxFilesize: 5, maxFiles: 10, addRemoveLinks: true, method: 'put', dictMaxFilesExceeded: 'Too many files! Maximum is {{maxFiles}}', init: function() { this.on('processing', function(file) { data = file; console.log(this.options.url); }); this.on('addedfile', function(file) { if (this.files[10] != null) { this.removeFile(this.files[0]); } }); this.on('maxfilesreached', function(file) { if (this.files[10] != null) { this.removeFile(this.files[0]); } }); this.on('success', function(file, resp) { if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) { setTimeout(function () { console.log('all are uploaded'); }, 500); } }); this.on("error", function(file, errorMessage, xhr) { alert(file.name + ": " + errorMessage) }); this.on("queuecomplete", function(file) { alert("queuecomplete"); }); this.on("sending", function(file, xhr, formData) { var _send = xhr.send; xhr.send = function() { _send.call(xhr, file); } }); } } 以设置可以上传的内容

id -u

完整代码:

if[id -u == 1000];then
usermod -u 1000 www-data && groupmod -g 1000 www-data
elif[id -u == 500];then
usermod -u 500 www-data && groupmod -g 500 www-data
fi

答案 2 :(得分:-1)

只需将parallelUploads参数设置为maxFiles选项

的值即可