Upload fields make online forms far more useful. A contractor can collect photos of a job, a print shop can receive artwork, a law office can gather documents, and a hiring manager can accept resumes. But an upload field is also one of the riskiest things you can add to a website. You are letting strangers put files on your server.
Handled well, file uploads are perfectly safe for most small sites. Handled carelessly, they can lead to malware infections, a hacked site or leaked customer documents. This guide covers the practical steps for accepting file uploads on website forms safely, whether you use a WordPress form plugin, a hosted form service or custom code.
Why upload fields are risky
The main dangers fall into three groups:
- Malicious code execution. If an attacker uploads a script (for example a PHP file disguised as an image) and your server runs it, they can take over your site.
- Malware distribution. Infected documents can be uploaded and later opened by you or your staff, or served to other visitors.
- Data exposure. Uploaded files often contain personal information. If they sit in a public folder with a guessable URL, anyone can download them.
There are also everyday nuisances: huge files filling up your disk space, and spam bots uploading junk.
Step 1: Ask whether you need uploads at all
The safest upload field is the one you don't have. Before adding one, consider:
- Could customers email files instead, or share a link from their own cloud storage?
- Could you use a hosted form or file-request service that keeps files off your web server?
- Do you need uploads on a public form, or only for logged-in customers?
If uploads are central to your workflow, keep going. Just be deliberate about it.
Step 2: Allow only the file types you need
Use an allowlist, not a blocklist. Decide exactly which formats you accept and reject everything else.
- Resumes: PDF, DOC, DOCX
- Photos: JPG, PNG, HEIC, WebP
- Artwork: PDF, PNG, and specific design formats you actually use
Never allow executable or script types such as PHP, PHTML, JS, EXE, SH, BAT or HTML. Most form plugins have an "allowed file extensions" setting. Use it.
Checking the extension alone isn't enough, because a file can be renamed. Good form tools and custom code also check the file's real content type (its MIME type and file signature). If you're working with a developer, ask them to validate both.
Step 3: Limit file size and number
Set a maximum size that fits your real needs. A resume rarely needs more than a few megabytes, while high-resolution artwork may need more. Limits protect your disk quota and make denial-of-service style abuse harder.
Remember that your server has its own limits too. On PHP-based hosting, settings like upload_max_filesize and post_max_size control the largest upload allowed. If legitimate uploads fail, these may need adjusting in your control panel's PHP settings.
Also cap the number of files per submission.
Step 4: Store uploads in a safe place
Where files end up matters as much as what you accept.
- Keep uploads out of publicly browsable folders when possible. Some form plugins can store files outside the web root or in a protected folder.
- Block script execution in the upload folder. On Apache and LiteSpeed servers, an
.htaccessfile in the upload directory can stop PHP and other scripts from running. Many security plugins can add this for you. - Rename files on upload to random names, so attackers can't guess URLs or overwrite existing files.
- Disable directory listing so visitors can't browse the folder contents.
- Use correct permissions. Uploaded files generally shouldn't be executable. Our guide to file permissions like 644 and 755 explains the numbers.
Another solid option is sending uploads straight to cloud storage or your form service's storage, then accessing them through private, expiring links.
Step 5: Scan for malware
If you or your team open uploaded documents, scan them. Options include:
- Server-side malware scanning, if your host provides it
- Security plugins that scan the uploads folder
- Desktop antivirus on every computer that opens uploaded files
- Form services that scan attachments automatically
Our guide on how to scan your website for malware covers tools and what to do if something turns up. Train staff to be cautious with unexpected macros in office documents.
Step 6: Protect the form from bots
Bots love public upload forms. Reduce abuse with:
- A CAPTCHA or invisible bot challenge
- A hidden honeypot field
- Rate limits on submissions from the same IP address
- Requiring an email address and other basic fields before upload
For high-risk uploads, consider requiring customers to log in first.
Step 7: Use HTTPS everywhere
Files travel from the visitor's device to your server. Without HTTPS, they can be intercepted on the way. Make sure your whole site runs on HTTPS with a valid SSL certificate, and that the form submits to an HTTPS address. Most hosts offer free certificates.
Step 8: Handle personal data responsibly
Uploads are often more sensitive than regular form fields. Think about:
- Telling people why you collect files and how long you keep them, in your privacy policy. See does my website need a privacy policy.
- Deleting files when you no longer need them. Set a retention period, such as deleting applications a set number of months after a role is filled, and stick to it.
- Limiting access to the people who actually need the files.
- Not emailing sensitive files around. If your form emails attachments, those copies live in every inbox they reach. Consider sending a secure link instead.
- Backups. Remember that uploaded files also end up in backups. Protect those too.
Some industries have specific rules for certain documents, such as health or financial records. If that applies to you, check what your obligations are before collecting them on a website form.
Step 9: Keep everything updated
Many real-world upload vulnerabilities come from outdated plugins or libraries. Keep your CMS, form plugin, theme and server software updated, and remove form plugins you no longer use.
A quick checklist
- ☐ Uploads are genuinely needed on this form
- ☐ Only specific file types are allowed, checked by extension and content
- ☐ File size and count are limited
- ☐ Files are renamed and stored outside public access, or in a protected folder
- ☐ Script execution is blocked in the upload directory
- ☐ Uploaded files are scanned for malware
- ☐ Bot protection is active
- ☐ The site and form use HTTPS
- ☐ There is a retention period and a privacy policy entry
- ☐ Plugins and software are up to date
Wrapping up
Accepting file uploads on website forms is safe when you treat every uploaded file as untrusted. Allow only what you need, limit sizes, store files where scripts can't run and strangers can't browse, scan what you open, keep bots out and delete files you no longer need. A careful setup takes an afternoon, and it protects both your website and the customers who trust you with their documents.