Dropzone设置acceptedFiles限制上传文件类型失效求助
It looks like the core issue is how you're targeting your Dropzone forms in the configuration script. Let's break this down and get it sorted out quickly.
The Root Cause
Your two upload forms have IDs mainDiv and recommendationDiv, but your script is trying to apply settings to a Dropzone instance with the ID dropzone—which doesn't exist in your HTML. Dropzone links configuration options to form IDs using the pattern Dropzone.options.[formId], so your current code isn't attaching the file type rules to either of your actual upload forms.
Solution 1: Configure Each Form Individually
If you want to keep using Dropzone's automatic initialization (it auto-initializes elements with the dropzone class), update your script to target each form's specific ID:
// Configure the first upload form (id="mainDiv") Dropzone.options.mainDiv = { acceptedFiles: 'image/*' }; // Configure the second upload form (id="recommendationDiv") Dropzone.options.recommendationDiv = { acceptedFiles: 'image/*' };
Solution 2: Unified Initialization (Cleaner for Identical Rules)
Since both forms share the same file type restriction, you can manually initialize all dropzone class forms with a single shared configuration to avoid repeating code:
// Initialize all forms with the "dropzone" class document.querySelectorAll('.dropzone').forEach(formElement => { new Dropzone(formElement, { acceptedFiles: 'image/*' }); });
Small Bonus Tip
I noticed your prompt text has duplicate "PDF" entries—you might want to clean that up for better clarity:
(Please upload PDF, JPG, GIF, PNG files only.)
内容的提问来源于stack exchange,提问作者Muhammad Umar

