• Gravitate

    (@gravitate)


    Currently there is no support for Gravity Forms Uploads.
    I would suggest that you look at adding this feature.
    It is relatively easy to add.

    It would be really nice if there as an option in the settings to include this.

    Review the code below as there are some variables and methods that would need to be modified to fit your plugin.

    // Filter Gravity Forms to upload files to S3
    add_filter('gform_upload_path', 'gform_change_upload_path_for_s3', 10, 2);
    add_action('gform_after_submission', 'gform_submit_to_s3', 10, 2);
    
    function gform_change_upload_path_for_s3($path_info, $form_id)
    {
    	$bucket_info = get_option('tantan_wordpress_s3');
    
    	$as3cf_is_active = {{{{ Check to See if AS3CF Plugin is Present and active and S3 Keys are added }}}};
    
    	if(!empty($bucket_info['bucket']) && $as3cf_is_active )
    	{
    		$gform_link = explode('wp-content/uploads/', $path_info["url"]);
    		$domain = $bucket_info['bucket'];
    
    		if($bucket_info['bucket'] == 'subdomain')
    		{
    			$domain = $bucket_info['bucket'].'.s3.amazonaws.com';
    		}
    		else if($bucket_info['bucket'] == 'path')
    		{
    			$domain = 's3.amazonaws.com/'.$bucket_info['bucket'];
    		}
    		else if($bucket_info['bucket'] == 'cloudfront')
    		{
    			$domain = $bucket_info['cloudfront'];
    		}
    
    		$protocol = ($bucket_info['ssl'] !== 'request' ? $bucket_info['ssl'] : 'http'.(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : ''));
    
    		$path_info["url"] = (strpos($domain, 'http') === false ? $protocol : '')."://".$domain.'/'.$gform_link[1];
    	}
    	return $path_info;
    }
    
    function gform_submit_to_s3($entry, $form)
    {
    	$bucket_info = get_option('tantan_wordpress_s3');
    
    	$as3cf_is_active = {{{{ Check to See if AS3CF Plugin is Present and active and S3 Keys are added }}}};
    
    	if(!empty($form['fields']) && !empty($bucket_info['bucket']) && $as3cf_is_active )
    	{
    
    	    ################################################################
    		######## THIS NEEDS TO BE CORRECTED TO CONNECT TO AS3CF S3 CLASS
    
    		require WP_CONTENT_DIR.'/plugins/amazon-web-services/vendor/aws/aws-autoloader.php';
    
    		$s3Client = S3Client::factory(array(
    		    'key'    => AWS_ACCESS_KEY_ID,
    		    'secret' => AWS_SECRET_ACCESS_KEY
    		));
    
    		################################################################
    
    		foreach ($form['fields'] as $field)
    		{
    			if($field->type == 'fileupload' && !empty($entry[$field->id]))
    			{
    				$gform_link = explode('/gravity_forms/', $entry[$field->id]);
    
    				$upload_dir = wp_upload_dir();
    
    				$file_url = $upload_dir['baseurl'].'/gravity_forms/'.$gform_link[1];
    				$url_parts = parse_url( $file_url );
    				$full_path = $_SERVER['DOCUMENT_ROOT'] . $url_parts['path'];
    
    				######## THIS NEEDS TO CONNECT TO AS3CF S3 CLASS
    				// Add the file to S3
    				$s3Client->putObjectFile($full_path, $bucket_info['bucket'], 'gravity_forms/'.$gform_link[1], S3::ACL_AUTHENTICATED_READ);
    			}
    		}
    	}
    }

    https://wordpress.org/plugins/amazon-s3-and-cloudfront/

  • The topic ‘Support for Gravity Forms Uploads’ is closed to new replies.