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

最佳答案

我假设您的页面中有一个变量,该变量来自控制器或任何类型的服务器端层,其值均为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 ?>",


    };

10-08 01:23