• Hello!

    First, WPFC7 is a magnificent addition to the WP community. Now, onto my issue.

    I have a file upload field that has been configured to allow video files to be uploaded/emailed. Much to my surprise, the files are not “left” on the server, they are actually deleted after they have been successfully emailed.

    I found this default configuration odd, considering the nature of my uploads. First, most of my uploaded files will never make it through as attachments in email, because of their sheer size, therefore, keeping them on the server is crucial.

    Second, the option to leave or delete is NOT an option controlled by the administrator via the WPCF7 administrative interface. I think in the next release, this should be an option.

    Leave on server? Yes/No

    I found the php strings that “cleans” up the files after they are successfully emailed. I commented the lines out to omit the cleanup function. Here it is:

    function wpcf7_cleanup_upload_files() {
    	$dir = trailingslashit( wpcf7_upload_tmp_dir() );
    
    	if ( ! is_dir( $dir ) )
    		return false;
    	if ( ! is_readable( $dir ) )
    		return false;
    	if ( ! is_writable( $dir ) )
    		return false;
    
    	if ( $handle = @opendir( $dir ) ) {
    		while ( false !== ( $file = readdir( $handle ) ) ) {
    			if ( $file == "." || $file == ".." || $file == ".htaccess" )
    				continue;
    
    			$stat = stat( $dir . $file );
    			if ( $stat['mtime'] + 60 < time() ) // 60 secs
    				@unlink( $dir . $file );
    		}
    		closedir( $handle );
    	}
    }
    
    if ( ! is_admin() && 'GET' == $_SERVER['REQUEST_METHOD'] )
    	wpcf7_cleanup_upload_files();

    Even after commenting these lines out, the files are not be left behind on the server.

    I have ensured that my “max upload” sizes and timeouts in my php.ini are sufficient. I have been testing with a file that is within parameter of my constraints.

    I have not specified an upload folder in my settings -> media. I am simply leaving it at its default of wp-content/uploads. Furthermore, I have defined WPCF&_UPLOADS_TMP_DIR in my wp-config.php to wp-content/uploads/wpcf7_uploads

    Lastly, my file permissions are all up to snuff, I currently have them wide open at 777.

    I am receiving the email with the attachment, but I plan on disabling this feature once I am able to successfully upload the files to the wpcf7_uploads directory.

    My error logs do not report any errors.

    Any help is greatly appreciated.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter F C

    (@pmagony)

    I was able to figure it out. If someone else reads this thread, locate:

    wp-content/plugins/contact-form-7/includes/controller.php

    Lines 95-97 need to be commented out.

    // remove upload files
    			/*foreach ( (array) $wpcf7_contact_form->uploaded_files as $name => $path ) {
    				//@unlink( $path );
    			*/}

    Hope this helps!

    I tried the suggestions you mentioned.

    I commented out the wpcf7_cleanup_upload_file function on the file.php file, and also lines 95-97 on the controller.php file.

    At first I received an error, but then I changed line 97 to }*/
    and the error went away.

    However the file still got deleted from the wpcf7_uploads folder, which is set to 777.

    Any suggestions?

    Thread Starter F C

    (@pmagony)

    “At first I received an error, but then I changed line 97 to }*/
    and the error went away.”

    Thanks for catching that typo.

    It’s odd that the file is still being deleted. I’m wondering if you uploaded/replaced the correct files. Double-check to see that the files are indeed being over-written with your new modifications.

    Check that your settings -> media is empty. And try defining the upload path in your wp-config.php to see if that helps.

    Is there allready a solution for this issue? This should not be that complicated for a competent programmer? However, I’m unfortunatly not an expert.

    Thread Starter F C

    (@pmagony)

    Frank, have you read the full thread? The solution exists.

    Unfortunatly the files are getting deleted even after editing controller.php just like trewknowledge said.

    I really would like to make content downloadable on an other part of the webpage after people submitted their stuff.

    YES!!!!

    Thanks, what a struggle.

    In Version 3.1 of Contact Form 7 the file with the code to be commented out in the wp-content/plugins/contact-form-7/includes directory is NOT controller.php (lines 95-97) instead it is classes.php (lines 294-296).

    The code is the same, just in a different location in version 3.1. Once commented out the uploaded file stays in the wp-content/uploads/wpcf7_uploads folder.

    This REALLY should be a settings option in the plugin configuration! Save the file? yes/no

    Thread Starter F C

    (@pmagony)

    I thought I would share additional information. In the new 3.1 version, the script creates an HTACCESS file in the wpcf7_uploads folder that denies access to all AND then “deletes” the file from the server after a predetermined amount of time.

    This is in plugins/contact-form-7/module/file.php, starting at lines 292 – end of file, you will see all the uploading functions. You’ll need to comment out various blocks to block htaccess and leave the file on the server:

    Lines: 299 – 306

    $htaccess_file = trailingslashit( $dir ) . '.htaccess';
    	if ( file_exists( $htaccess_file ) )
    		return;
    
    	if ( $handle = @fopen( $htaccess_file, 'w' ) ) {
    		fwrite( $handle, "Deny from all\n" );
    		fclose( $handle );
    	}

    Lines: 316 – 340

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Thread Starter F C

    (@pmagony)

    If you want to “replace” an existing file, without renaming it, see this thread: https://www.ads-software.com/support/topic/plugin-contact-form-7-replace-same-name-file-after-upload?replies=4#post-2714097

    Hi@all.
    First of all, a big thanks to pmagony. Everything works fine.

    The only problem is, I also use Contact Form 7 to Database Extension” to “record” all incoming messages. After editing the code, there is no link shown to the uploaded files anymore. I don’t know why. It’s frustrated because now I always have to compare the uploadtimes to find the correct files on the FTP.

    I think the answer is hidden in the out commented wpcf7_cleanup_upload_files function, but I cant find it. ??

    Any idea?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Plugin: Contact Form 7] Leave file upload on server.’ is closed to new replies.