Tech
Contact Form 7 File Upload Not Working: Size & Type Limits
CF7 file upload failing? We tested limit: syntax, filetypes and PHP upload_max_filesize on 6.2.4.1. See which settings are silently ignored and how to fix them.
A visitor picks a file, presses Send, and gets “There was an error uploading the file.” Or the form works for your test PDF and fails for a customer’s. File upload is the part of Contact Form 7 (CF7) where most “it silently does nothing” tickets come from, because three separate limits are involved and only one of them is CF7’s.
We downloaded the current release from WordPress.org on November 4, 2026 and ran its own code against the option strings people actually type. This article lists what is enforced, what is quietly ignored, and the exact settings that fix each symptom.
What we tested
| Item | Value |
|---|---|
| Plugin | Contact Form 7 6.2.4.1 (current stable) |
| Zip file | contact-form-7.latest-stable.zip, 414,335 bytes |
| md5 of the zip | df9fd5571996b7007471852a8f2cd36c |
| PHP used for the tests | 8.3.6 (CLI), which matches the plugin’s “Requires PHP: 8.3” header |
| Files read | modules/file.php, includes/file.php, includes/form-tag.php, vendor/rocklobsterinc/swv/src/Rules/ and includes/swv/js/index.js |
For the option parsing we loaded the plugin’s real get_limit_option() and wpcf7_acceptable_filetypes() functions with a minimal WordPress stub and fed them different strings. For the PHP limits we started PHP’s built-in web server with different upload_max_filesize and post_max_size values and posted a file with curl. Nothing below is guesswork copied from older tutorials.
The three limits that can block an upload
Think of an upload passing through three gates, in this order:
- PHP’s gates (
upload_max_filesize,post_max_size). They run before WordPress loads. - CF7’s size gate (the
limit:option). It runs in the browser first, then again on the server. - CF7’s type gate (the
filetypes:option). Same two-stage check.
When people say “I set limit:10mb and it still fails,” the file is almost always stopped at gate 1. CF7 never gets to look at it.
Gate 1: PHP stops the file before CF7 sees it
We posted a 3,000,000-byte file with a text field to a test server in two configurations.
| PHP setting | What PHP handed to the script |
|---|---|
upload_max_filesize=2M, post_max_size=8M | The text field arrived. The file came through with error code 1 and size 0. |
upload_max_filesize=8M, post_max_size=2M | Nothing arrived at all: 0 text fields, 0 files. |
| Default setup, a 1,000,000-byte file | Error code 0, size 1000000. Normal upload. |
The first row is the common one. CF7’s server code in wpcf7_unship_uploaded_file() loops over the error codes and returns the message upload_failed_php_error for any non-zero code except “no file.” The default text of that message is “There was an error uploading the file.” That is different from “The uploaded file is too large,” which only CF7’s own limit: check produces.
So the wording tells you where it failed:
- “The uploaded file is too large.” means CF7’s
limit:rejected it. Raiselimit:. - “There was an error uploading the file.” means PHP rejected it. Raise
upload_max_filesize. - If the whole request is larger than
post_max_size, PHP discards everything: in our second test the script received 0 text fields and 0 files. CF7 then has nothing to validate, and what the visitor sees depends on the site. Raisepost_max_size.
Set both values higher than the largest file you intend to accept. post_max_size has to cover the whole request, which includes every other field and the multipart overhead, so keep it a little above upload_max_filesize:
; php.ini (or .user.ini on many shared hosts)
upload_max_filesize = 10M
post_max_size = 12M
To see what the web server really uses, open Tools → Site Health → Info → Server in WordPress, which lists the upload and post size limits. Do not trust WP-CLI or a hosting panel for this: the command line often loads a different php.ini than the web server does, and the value that counts is the one PHP reports to web requests.
CF7 does warn about one half of this. In includes/config-validator/form.php it compares upload_max_filesize with each tag’s limit and raises a warning in the form editor when the limit is larger. It does not look at post_max_size.
Gate 2: the limit: option is stricter than it looks
The documented syntax is limit: followed by a number and an optional kb or mb. The pattern in includes/form-tag.php is:
/^limit:([1-9][0-9]*)([kKmM]?[bB])?$/
Anything that does not match is ignored, and the function returns the default, 1 MB. There is no error and no warning. We ran each of these through the real method:
| What you typed | Bytes CF7 used | Result |
|---|---|---|
limit:2mb | 2,097,152 | Works |
limit:2MB | 2,097,152 | Works (case-insensitive) |
limit:500kb | 512,000 | Works (kb means 1,024 bytes, so 500 × 1,024) |
limit:10485760 | 10,485,760 | Works (plain bytes) |
limit:2m | 1,048,576 | Ignored. Falls back to 1 MB |
limit:5M | 1,048,576 | Ignored. Falls back to 1 MB |
limit:2.5mb | 1,048,576 | Ignored. Decimals do not match |
limit:0 | 1,048,576 | Ignored. The number must start with 1 to 9 |
limit:2 mb | 2 | Two bytes. The space splits the option, so only limit:2 is read |
limit:2mb limit:5mb | 2,097,152 | The first match wins |
Two of these deserve a closer look.
limit:5M looks right and is wrong. The unit has to be kb or mb; a bare m or k does not match. The result is a form that rejects a 3 MB file while you are certain you allowed 5.
limit:2 mb is worse. It is read as a limit of 2 bytes, so every real file fails with “The uploaded file is too large,” and nothing in the form tells you why. If a limit “does nothing” or blocks everything, look at the tag in the form editor for a stray space.
A working tag looks like this:
[file* attachment limit:10mb filetypes:pdf|docx|jpg|png]
One more detail from the source: the size check adds up all files in the field and compares the total with the limit (array_reduce in the server rule, reduce in the browser rule). It is not a per-file check. In 6.2.4.1 modules/file.php we found no code that adds the multiple attribute to the input, so a [file] tag normally carries one file. If you add multiple yourself or use a plugin that does, remember that the limit applies to the combined size.
Gate 3: filetypes: accepts extensions, not categories
If you leave filetypes: out, CF7 allows audio/*, video/* and image/*. That default is hard-coded in wpcf7_acceptable_filetypes(). A PDF, a Word file or a ZIP is therefore rejected by default with “You are not allowed to upload files of this type.” Many people only discover this after launch because their test file was a JPG.
We called the real function with the values people usually try:
filetypes: value | HTML accept attribute | Server regex list |
|---|---|---|
| (omitted) | audio/*,video/*,image/* | All audio, video and image extensions known to WordPress |
pdf|docx | .pdf,.docx | pdf|docx |
.pdf | .pdf | pdf |
application/pdf | application/pdf | pdf |
jpg|png | .jpg,.png | jpg|png |
text/* | (empty) | (empty) |
The last row is the trap. In the attribute branch, the code only keeps a type/* wildcard when the top-level type is audio, video or image; anything else is dropped. text/* and application/* therefore turn into nothing. List the extensions you want instead (filetypes:csv|txt|pdf).
The table above used a short stand-in list of MIME types, so the exact extension list for image/* on your site will be longer. The behaviour is what matters: a MIME type is converted to the extensions WordPress knows for it.
It is an extension check, not a content check
Both the browser rule (includes/swv/js/index.js) and the PHP rule (FileRule) decide by looking at the end of the file name: name.toLowerCase().endsWith(extension). The file’s contents are never opened. A file called report.pdf that is really something else passes a filetypes:pdf field.
That is fine for a contact form where you want to stop honest mistakes. It is not a defence against a hostile upload. The upload is also not saved where visitors can fetch it: the file is moved into wp-content/uploads/wpcf7_uploads/<random directory>/, it is made readable only by its owner (chmod 0400), and CF7 writes an .htaccess with “Require all denied” into the parent folder. Servers that ignore .htaccess (Nginx, for example) need an equivalent rule of their own.
The file is deleted a minute later
If your workflow depends on the file being in WordPress afterwards, note that CF7 sweeps the temporary folder. wpcf7_cleanup_upload_files() runs on shutdown and removes anything older than 60 seconds, at most 100 items per request. The only lasting copy is the email attachment. We cover the storage side in Contact Form 7 does not save submissions.
Two practical settings follow from that:
- In the Mail tab, put the field name under File attachments (for example
[attachment]). Pasting[attachment]into the body only prints the file name (the mail tag returns the base name, not the file). - Large attachments make the mail itself fail on strict providers. If uploads pass validation but the email never arrives, work through the SMTP and SPF/DKIM checks.
If you want the temporary files somewhere else, define the folder in wp-config.php. The path is relative to wp-content:
define( 'WPCF7_UPLOADS_TMP_DIR', 'private-uploads' );
The code only accepts the directory if it resolves inside wp-content.
Cleaning up file names
CF7 already runs file names through wpcf7_antiscript_file_name(), and wp_unique_filename(). If you also want to drop the visitor’s original name from your records, the wpcf7_upload_file_name filter (called with the cleaned name, the original name and the tag options) is the place:
add_filter( 'wpcf7_upload_file_name', function ( $filename, $original, $options ) {
$ext = pathinfo( $filename, PATHINFO_EXTENSION );
return wp_generate_password( 12, false ) . ( $ext ? '.' . $ext : '' );
}, 10, 3 );
This keeps the extension, so the filetypes: rule still matches, and the visitor never sees a difference. We ran php -l on the snippet with PHP 8.3.6 and it parses cleanly.
WordPress Plugin
Never lose a lead to a failed email.
Frontierline Forms keeps a submission log for every Contact Form 7 form, so the text fields survive even when a large attachment makes the notification email bounce. The free version covers the log, confirmation screen and multi-step forms.
A checklist for “my upload fails”
Work from the outside in:
- Read the exact message. “Too large” is CF7’s
limit:. “Error uploading the file” is PHP. - Check
ini_get()at runtime forupload_max_filesizeandpost_max_size; both must exceed your limit. - Inspect the tag for
limit:5M, decimals, or a space between the number andmb. - Add
filetypes:if you expect anything other than audio, video or images, and list extensions, notapplication/*. - Put the field in “File attachments” in the Mail tab, then test with a file near the limit, not a tiny one.
- Check the mail log. Validation can pass while the provider refuses a 10 MB message.
Make the limit visible to visitors
CF7 only tells people about the limit after they fail. Say it before. A short line under the field avoids most support emails:
<label>Attach your CV (PDF or Word, up to 10 MB)
[file* attachment limit:10mb filetypes:pdf|docx]</label>
Keep the text in sync with the tag. Because limit: silently falls back to 1 MB when it cannot be parsed, a label that promises 10 MB over a broken tag is the most common cause of a visitor being turned away with no explanation.
WordPress Plugin
Keep your Contact Form 7 forms. Add what they lack.
Frontierline Forms adds a confirmation screen, multi-step flow and submission log to the forms you already have. Free on WordPress.org; Pro starts at $39.99 per year.