# File path or url to the uploads folder to use when creating thumbnails

**URL:** <https://community.gravityforms.com/t/file-path-or-url-to-the-uploads-folder-to-use-when-creating-thumbnails/13398>\
**Category:** Get Help\
**Tags:** file-uploads, gform\_file\_upload\_markup, get\_upload\_root\_info\
**Created:** [September 8, 2022, 12:11am UTC](https://community.gravityforms.com/t/file-path-or-url-to-the-uploads-folder-to-use-when-creating-thumbnails/13398 "2022-09-08T00:11:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maryb](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/maryb/32/5793_2.png) [@maryb](https://community.gravityforms.com/u/maryb)\
**Post date:** [September 8, 2022, 12:11am UTC](https://community.gravityforms.com/t/file-path-or-url-to-the-uploads-folder-to-use-when-creating-thumbnails/13398/1 "2022-09-08T00:11:00Z")

</div>

Hi, some time ago I had a function written for me that creates thumbnail images of the fileuploads. See below, I now need the thumbnails to go into the same folder as the uploads I can’t work out how to do it  
Thanks 🙂

```auto
/*create thumbnails*/
add_action( 'gform_after_submission', 'iss_gf_flash_after_submission', 10, 2 );
function iss_gf_flash_after_submission($entry, $form) {
  //Walk through the form fields and find any file upload fields
  foreach ($form['fields'] as $field) {
    if ($field->type == 'fileupload') {
      //See if an image was submitted with this entry
      if (isset($entry[$field->id])) {
        $fileurl = $entry[$field->id];

				// Get the path to the upload directory.
				$wp_upload_dir = wp_upload_dir();

				//Gravity forms often uses its own upload folder, so we're going to grab whatever location that is
				$parts = explode('uploads/', $entry[$field->id]);
				$filepath = $wp_upload_dir['basedir'].'/'.$parts[1];
				$fileurl = $wp_upload_dir['baseurl']. '/'.$parts[1];
				$filename = basename( $filepath );
				$ext = pathinfo($filename, PATHINFO_EXTENSION);
				$filesuffix = 'thumb';

				$dest_path = $wp_upload_dir['basedir'].'/gravity_forms/thumbs';
				$max_w = 170;
				$max_h = 170;
				$crop = false;

				if (strtolower($ext) == 'png' || strtolower($ext) == 'jpg' || strtolower($ext) == 'jpeg' || strtolower($ext) == 'gif') {
						//Create a custom thumbnail in the GF thumbs directory with suffix '-thumb'
					$thumbname = $wp_upload_dir['basedir'].'/gravity_forms/thumbs/'.str_replace('.'.$ext, '', $filename).'-thumb.'.strtolower($ext);

					$image = wp_get_image_editor( $filepath );
					var_dump($image);
					if ( ! is_wp_error( $image ) ) {
					    $image->resize( $max_w, $max_h, $crop );
					    $image->save( $thumbname );
					}
					
					} else if(strtolower($ext) == 'psd' || strtolower($ext) == 'tif' || strtolower($ext) == 'tiff') {
					$thumbname = $wp_upload_dir['basedir'].'/gravity_forms/thumbs/'.str_replace('.'.$ext, '', $filename).'-thumb.jpg';

					$image = wp_get_image_editor( $filepath );
					var_dump($image);
					if ( ! is_wp_error( $image ) ) {
					    $image->resize( $max_w, $max_h, $crop );
					    $image->save( $thumbname );
				}
		
				
				} 

      }
    }
  }
};

```

---

<div class="post-metadata">

**Author:** ![sacom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sacom/32/53_2.png) [@sacom](https://community.gravityforms.com/u/sacom)\
**Post date:** [September 8, 2022, 1:41pm UTC](https://community.gravityforms.com/t/file-path-or-url-to-the-uploads-folder-to-use-when-creating-thumbnails/13398/2 "2022-09-08T13:41:58Z")

</div>

You can use this to get the current upload path for your form:

```auto
$form_upload_root = GF_Field_FileUpload::get_upload_root_info( $form['id'] );

```

That would return an array like this:

```auto
(
    [path] => /var/www/public_html/wp-content/uploads/gravity_forms/3607-a558b73f9c31ba912c47174193fa3d03/2022/09/
    [url] => http://example.com/wp-content/uploads/gravity_forms/3607-a558b73f9c31ba912c47174193fa3d03/2022/09/
    [y] => 2022
    [m] => 09
)

```

So you can update your snippet to use `$form_upload_root['path']` to store your thumbnails.

---

<div class="post-metadata">

**Author:** ![maryb](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/maryb/32/5793_2.png) [@maryb](https://community.gravityforms.com/u/maryb)\
**Post date:** [September 9, 2022, 3:11am UTC](https://community.gravityforms.com/t/file-path-or-url-to-the-uploads-folder-to-use-when-creating-thumbnails/13398/3 "2022-09-09T03:11:28Z")

</div>

Thanks so much Samual I’ll give it a go

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/f/fef63f0599c45e0218c30d9f5d7ca8bff9b00189.png) [@system](https://community.gravityforms.com/u/system)\
**Post date:** [October 9, 2022, 3:11am UTC](https://community.gravityforms.com/t/file-path-or-url-to-the-uploads-folder-to-use-when-creating-thumbnails/13398/4 "2022-10-09T03:11:35Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
