Skip to content

Store each entry’s images in a separate directory

By default, Image Hopper stores all uploaded images for a form in a shared directory structure: /wp-content/uploads/gravity_forms/{$form_id}_{$hash}/{$year}/{$month}/. This means multiple entries can share the same folder, and filename conflicts are resolved by appending an incremental suffix. If you prefer to store each entry’s images in a separate directory instead, use this snippet.

Store each entry’s images in a dedicated directory:

// Use a unique directory for each form entry.
add_filter( 'gform_upload_path', function( $path_info, $form_id ) {
  $unique_id = rgpost( 'gform_unique_id' );
  $hash  = json_encode( $_SERVER );
  $state = wp_hash( crc32( $unique_id . $hash ) );

  $path_info['path'] = WP_CONTENT_DIR . "/files/$form_id/{$state}/";
  $path_info['url']  = WP_CONTENT_URL . "/files/$form_id/{$state}/";

  return $path_info;
}, 10, 2 );

This filter generates a unique hash per entry based on the gform_unique_id and server environment, so each submission lands in its own folder.