Simplify Your Email Testing Process!
Are you tired of the hassle and uncertainty when testing your emails? Look no further than MailMug.net! You can easily test the attached files with the MailMug.net test SMTP server.Contact form 7 File Upload (cf7 file upload) Shortcode Generator
Sample Shortcode (file upload example)
[file* your-image]
File Tag Options
OPTION | EXAMPLES | DESCRIPTION |
---|---|---|
id:(id) | id:some-id |
id attribute form file input tag. |
class:(class) | class:some-class-here |
class: the attribute value of the input element. One or more classes are possible, like [file your-file class:col-md-2 class:m01 class:pt-1] . |
filetypes:(filetypes) | filetypes:gif|jpg|jpeg|png
OR
image/*|txt|application/pdf |
Add acceptable file types after filetypes: Multiple file types are separated with the (pipe) '|' character. You can specify file types using their extensions or MIME types. |
limit:(num) | limit:2043576
limit:3024kb
limit:3mb |
Maximum upload file size. (i.e., like this: [file your-file limit:1.5mb] ) |
Acceptable File Types
Contact form 7 default acceptable file types are jpg, jpeg, png, gif, pdf, doc, docx, ppt, pptx, odt, avi, ogg, m4a, mov, mp3, mp4, mpg, wav and wmv.
You can specify file types using their extensions or MIME types.
Attach File to Mail
Just go to WP-admin > contact form 7 ( created form) > mail > file attachments add your file input tag as in image.File Upload Validation
File type and size validations are built. jpg, png,jpeg, gif, pdf, doc, docx, ppt, pptx, odt, avi, ogg, m4a, mov, mp3, mp4, mpg, wav, and wmv are default file extensions. Customize is possible just add filetypes: in the shortcode. Example: [file your-file filetypes:png|jpeg] File type not allowed message will get ( you are not allowed to upload files of this type ) If we upload gif, zip or any other file type (in this example).File upload size limit
1048576 bytes (1 MB) is the default file size limit. Customize file size with limit: option. The default number is in bytes but we can add by Mb or Kb. We can see an error message, "The file is too big" if we upload a file bigger than the limit. Example : [file your-file limit:2Mb]Image Upload Dimension Validation
CF7 image upload width and size validation code. Add filter for 'wpcf7_validate_file' . [file* your-image filetypes:gif|jpg|jpeg|png] Add the following code in your theme functions.php file or custom plugin file. Here, the minimum width and height is 300px. [crayon-67d42a262ec34677232599/]The Contact form 7 file upload not working?
Have you got an error message, "There was an unknown error uploading the file"? We can fix it by following the steps.First step:
Check wp-content/uploads/wpcf7_uploads folder is writable (755 - 777 ) or not. It should writable folder. Make sure your wpcf7_uploads should writable. For Linux and Mac OS, We can change folder permissions by the following command. [crayon-67d42a262ec42525951983/] Please try with 777, if it is not working. But 777 is not good practice.Second step:
Check your PHP maximum upload file size. We can check the maximum file upload size inwp-admin > Media > Add New
, We can see "Maximum upload file size: (num) MB". The maximum upload file size should be greater than your upload file size (Contact form 7 file shortcode size).
Method 1: Change the maximum upload size with a php.ini file
Add or change the upload_max_filesize, post_max_size, and memory_limit as bellow in the php.ini file.
[crayon-67d42a262ec44837544645/]
Now you can upload a maximum 20Mb file. You can change this value according to your needs.
Method 2: Change the maximum file upload size with a .htaccess file
Add the following lines of code in your root .htaccess file. You can add the last part of your .htaccess file.
[crayon-67d42a262ec4b492170101/]
Method 3: Change maximum file upload size with wp-config.php or selected theme functions.php file
Add the following line of codes in the wp-config.php or theme functions.php file.
[crayon-67d42a262ec4c644420152/]
File Upload Path
By default wp-content/uploads/wpcf7_uploads is a temporary upload file path. Files will be deleted immediately after a few seconds. You can change the temporary folder name byWPCF7_UPLOADS_TMP_DIR
constant in wp-config.php.
[crayon-67d42a262ec4d158533700/]
How to save the attached file to the server (Develop CRM)?
Install the column-based database addon. You can save submissions to the external or internal database. It will automatically create new tables for each CF7 form and separate MySQL columns for each input field.Does Contact Form 7 data and files save to the database?
We can't save submission data without additional extensions. We can use column-based database addon or CFDB7 plugin to save submissions to the MySQL database.Where do Contact Form 7 Submissions go?
We can catch post data by action hook. But it needs advanced knowledge in programming. We can use column-based database addon or CFDB7 plugin to save data.Get uploaded files by code
Save uploaded files by custom plugin or theme functions.php file. We can catch uploaded files bywpcf7_before_send_mail
action hook and WPCF7_Submission
class instance. WPCF7_Submission
class is a singleton class. It means it instantiates only one time. We can access it like an object by function. Check the following example code.
[crayon-67d42a262ec4f305478092/]
We can copy for move uploaded the file by move_uploaded_file PHP function before sent mail. This file will automatically delete after the sent mail.