【问题标题】:Change the default functionalites of dropzone.js更改 dropzone.js 的默认功能
【发布时间】:2016-01-21 09:57:46
【问题描述】:

我正在尝试使用 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.",

【问题讨论】:

  • 我认为您在每次加载的 php 文件中创建全局 javascript 变量,例如: 并在 dropzone js 中使用您的脚本变量
  • 我尝试了一个新的,看看我的答案

标签: javascript php image dropzone.js


【解决方案1】:

我假设您的页面中有一个变量来自控制器或任何类型的服务器端层,其值为maxFiles。 如果您使用的是 PHP,那么您需要做的就是设置 maxFiles: "<?php echo $maxfiles ?>" 或者如果您使用的是 laravel Blade,您可以使用

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

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

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

profilePicture.options.profilePicture = {

       // any other options

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


    };

【讨论】:

    【解决方案2】:
    <script type="text/javascript">
    Dropzone.options.yourid={
      maxFiles:5
    };
    </script>
    

    保留图像字段的 id 作为您的 id 在脚本中传递该 id 并为您需要更改的字段分配值并通过此方法输入值我们可以更改 dropzone.js 的默认功能

    【讨论】:

      猜你喜欢
      • 2013-07-16
      • 2018-06-04
      • 1970-01-01
      • 1970-01-01
      • 2016-05-13
      • 2020-05-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多