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
/*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 );
}
}
}
}
}
};