WordPress.org

Forums

Contact Form 7
[resolved] Change how file upload works (3 posts)

  1. mozrelic
    Member
    Posted 10 months ago #

    If I understand Contact Form 7s' documentation correctly, after a file is uploaded using a form, it is held temporarily, then deleted.

    This excerpt is from said documentation on http://contactform7.com/file-uploading-and-attachment/:

    "...At this point, Contact Form 7 attaches the file to the mail and sends it. After these procedures, Contact Form 7 then removes the file from the temporary folder."

    Is it possible to keep Contact Form 7 from removing the uploaded file? If so, how do I go about modifying the plugin to do so. I assume /modules/file.php is responsible for how this function of CF7 is handled.

    Any help would be very much appreciated, and if I can provide useful information, please let me know.

    https://wordpress.org/plugins/contact-form-7/

  2. CRMiller2014
    Member
    Posted 10 months ago #

    I would like to have my Contact form 7 function this way as well (saving the files submitted per the form vs. emailing, as I expect large files to be sent). Please let me know if you find the solution. Thanks.

  3. mozrelic
    Member
    Posted 10 months ago #

    So, I have solved this. It is necessary to modify code in two different files in the plugin for this to work. However it must be noted that if you modify these files, and choose to update CF7 in the future, your changes will be lost and this functionaly will be lost, and you will probably have to repeat these steps.

    If @Takayuki has a better solution for this, it would be great if he could post it.

    In the plugin file structure, look for modules/files.php

    Comment out line 346

    // @unlink( $dir . $file );

    The next file is includes/submission.php

    Comment out line 157
    // $this->remove_uploaded_files();

    And also lines starting at 278 to 282

    /*
    public function remove_uploaded_files() {
    		foreach ( (array) $this->uploaded_files as $name => $path ) {
    			@unlink( $path );
    		}
    	}
    */

    If you are attempting to upload files larger than 2mb you will need to make appropriate changes to .htaccess and perhaps php.ini, aswell as in the CF7 file field, but this information can be found in other places and I will not address this here.

Reply

You must log in to post.

About this Plugin

  • Contact Form 7
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic