Home › Forums › Contact Forms › Contact Form 7 File Upload – [2019]
Tagged: Contact form 7 File Upload
This topic contains 1 reply, has 1 voice, and was last updated by admin 5 months ago.
-
AuthorPosts
-
July 10, 2019 at 5:43 am #189
Contact form 7 file upload complete details with some other optional plugin also. It is describing, how to avoid not working issues not uploading issues etc.
Contact Form 7 file upload in a professional way. You can enable file attachment feature to your form. You will receive the attached file by email or you can store it in your server also by Contact Form 7 Database plugin.
Contact form 7 File Upload (cf7 file upload) Shortcode Generator
Sample Shortcode (file upload example)
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 theinput
element. One or more class is possible, like[file your-file class:col-md-2 class:m01 class:pt-1]
.filetypes:(filetypes) filetypes:gif|jpg|jpeg|png
Add acceptable file types after filetypes:
Multiple file types are separated with (pipe) ‘|’ character.limit:(num) limit:2043576
limit:3024kb
limit:3mb
Maximum upload file size. (i.e., like this: [file your-file limit:1.5mb]
)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.
You can add more input field one by one like [your-image][your-image2] like that. Mostly developer forgot to add file attachment tag to file attachment section. So Contact form 7 file attachment not sending or not receiving attachments is a common problem.
File Upload Validation
File type and size validations are inbuilt. 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]
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 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 the command.
1sudo chmod 755 wp-content/uploads/wpcf7_uploadsPlease 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 maximum file upload size in
wp-admin > Media > Add New
, We can see “Maximum upload file size: (num) MB”. Maximum upload file size should greater than your upload file size (Contact form 7 file shortcode size).Method 1: Change 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.
12345upload_max_filesize = 20Mpost_max_size = 21Mmemory_limit = 15max_execution_time = 300max_input_time = 300Now you can upload a maximum 20Mb file. You can change this value according to your needs.
Method 2: Change maximum file upload size with a .htaccess file
Add the following lines of code in your root .htaccess file. You can add last part of your .htaccess file.
123456789php_value upload_max_filesize 64Mphp_value post_max_size 128Mphp_value memory_limit 256Mphp_value max_execution_time 300php_value max_input_time 300Method 3: Change maximum file upload size with wp-config.php or selected theme functions.php file
Add the following line of codes in wp-config.php or theme functions.php file.
123@ini_set( 'upload_max_size' , '64M' );@ini_set( 'post_max_size', '64M');@ini_set( 'max_execution_time', '300' );File Upload Path
By default wp-content/uploads/wpcf7_uploads is temporary upload file path. Files will delete immediately after few seconds. You can change the temporary folder name by
WPCF7_UPLOADS_TMP_DIR
constant in wp-config.php.1define( 'WPCF7_UPLOADS_TMP_DIR', '/your/file/path' );How to save the attached file to the server?
Install the CF7 database plugin to your WordPress website. It is a free and popular plugin. You can see and download files in the admin dashboard. It allows downloading submissions as a csv file. No need any extra configuration. It is 100% automatic. You can contribute to improving CFDB7 plugin. Fork it on GitHub and pull the request. [Github – CFDB7]
Get uploaded files by code
Save uploaded files by custom plugin or theme functions.php file. We can catch uploaded file by
wpcf7_before_send_mail
action hook andWPCF7_Submission
class instance.WPCF7_Submission
class is a singleton class. It means it instantiates only one time. We can access as an object byget_instance()
function. Check the following example code.123456add_action('wpcf7_before_send_mail', 'save_application_form' );function save_application_form($wpcf7) {$submission = WPCF7_Submission::get_instance();$files = $submission->uploaded_files();}We can copy for move uploaded the file by move_uploaded_file PHP function before sent mail. This file will automatically delete after sent mail.
Multiple File Upload
CF7 default plugin does not allow to upload multiple files. But some other paid plugins are available.
Drag and drop files upload input
Upload multiple files with drag and drop and preview option. [More Details]
Multiple file upload input
It is similar to default contact form 7 file upload shortcode but multiple file upload option is enabled. [More Details]
Field repeater plugin
Repeat input fields by clicking on the add button or remove by clicking on the remove button. [More Details]
Note:- Please share your contact form 7 bugs or anything related CF7 plugin. We can solve.
-
July 10, 2019 at 10:19 am #227
Customize file upload validation error messages
Go to contact form 7 form > messages tab. Then set the custom message in the input field.
-
AuthorPosts
You must be logged in to reply to this topic.