更改dropzone.js的默认功能

时间:2016-01-21 09:57:47

标签: javascript php image dropzone.js

我正在尝试使用dropzone.js上传图像文件,并且我已使用该功能成功上传了它。我需要设置上传文件的限制,限制应该动态设置。我试图通过在js中的" maxFiles"变量上插入php代码来改变dropzone.js中的限制但是我失败了。

你们中的任何人都可以帮我解决这个问题吗? 我附加了dropzone.js的默认值我需要更改maxFiles的值动态建议我可能的解决方案。 提前谢谢

  url: '?do=uploadimage',
  method: "post",
  withCredentials: false,
  parallelUploads: 2,
  uploadMultiple: false,
  maxFilesize: 1,
  paramName: "file",
  createImageThumbnails: true,
  maxThumbnailFilesize: 1,
  thumbnailWidth: 120,
  thumbnailHeight: 120,
  filesizeBase: 1000,
  maxFiles: null,
  params: {},
  clickable: true,
  ignoreHiddenFiles: true,
  acceptedFiles: null,
  acceptedMimeTypes: null,
  autoProcessQueue: true,
  autoQueue: true,
  addRemoveLinks: true,

  previewsContainer: null,
  hiddenInputContainer: "body",
  capture: null,
  dictDefaultMessage: "Drag Files here or Click to Upload",
  dictFallbackMessage: "Your browser does not support drag'n'drop file uploads.",
  dictFallbackText: "Please use the fallback form below to upload your files like in the olden days.",
  dictFileTooBig: "File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize         }}MiB.",
  dictInvalidFileType: "You can't upload files of this type.",
  dictResponseError: "Server responded with {{statusCode}} code.",
  dictCancelUpload: "Cancel upload",
  dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?",
  dictRemoveFile: "Remove",
  dictRemoveFileConfirmation: null,
  dictMaxFilesExceeded: "You can not upload any more files.",

2 个答案:

答案 0 :(得分:1)

我假设您的页面中有一个变量,该变量来自控制器或任何类型的服务器端层,其值为maxFiles。 如果您使用的是PHP,则只需设置maxFiles: "<?php echo $maxfiles ?>"即可;如果您使用的是laravel刀片,则可以使用

'maxFiles': "{{ $maxFiles }}"

确保变量周围有双引号。我认为所有服务器端语言的想法都是相同的

profilePicture = new Dropzone('#profile-picture', {
    url: "/storeProfilePicture.php",
});

profilePicture.options.profilePicture = {

       // any other options

        maxFiles: "{{ $maxFiles }}",
        // OR
        maxFiles: "<?php echo $maxFiles ?>",


    };

答案 1 :(得分:0)

<script type="text/javascript">
Dropzone.options.yourid={
  maxFiles:5
};
</script>

保持图片字段的id,因为你的id在脚本中传递了id,并为你需要更改的字段赋值,并通过这种方法输入值,我们可以更改dropzone.js的默认功能