Thursday, January 26, 2023
HomeWordPress Developmentcapabilities - Tips on how to overwrite picture if it already exists...

capabilities – Tips on how to overwrite picture if it already exists – WordPress, Gravity type


How do I make the outdated file changed when the consumer uploads a brand new one?

Now the information are named a1.jpg, a2.jpg, a3.jpg. If the consumer uploads a.jpg, then I need to overwrite the a.jpg that already exists. This shall solely apply to this folder / type.

I exploit final member along with gravity varieties and gravity view. Have a type the place the proprietor of the function (firm) can add their very own firm emblem. It will get the renamed to the consumer function and is positioned in a particular folder.

Up to now I’ve managed to do that:

  • Rename the file to the consumer’s function – Carried out
  • Put the file in a devoted folder – Carried out
  • If the picture already exists, overwrite it – Not finished

The complete code could be discovered right here:
https://github.com/gravitywiz/snippet-library/blob/grasp/gravity-forms/gw-gravity-forms-rename-uploaded-files.php

The configuration in capabilities

# Configuration

new GW_Rename_Uploaded_Files( array(
'form_id' => 10,
'field_id' => 6,
// most merge tags are supported, authentic file extension is preserved
'template' => '{Position:7}',
// Ignore extension when renaming information and hold them in sequence (e.g. a.jpg, a1.png, a2.pdf and so on.)
'ignore_extension' => false,
) );

To place the information within the appropriate folder:

add_filter( 'gform_upload_path_10', 'change_upload_path', 10, 2 );
perform change_upload_path( $path_info, $form_id ) {
    $path_info['path'] = '/var/www/vhosts/instance.com/httpdocs/wp-content/uploads/company_logos/';
    $path_info['url'] = 'https://instance.com/wp-content/uploads/company_logos/';
    return $path_info;
}

Up to now every part is nice. The one drawback I’ve is that when the consumer uploads or adjustments the picture, it ought to overwrite the outdated one. Now when the consumer uploads a brand new one, they’re named firm.jpg, company1.jpg, company2.jpg and so on.

How do I make the outdated file changed?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments