Overwrite or replace previously uploaded file

I’m using gravity forms to facilitate file uploads to specified SFTP locations. To do this I’m successfully using the gform_upload_path_#ID filter to specify upload path. However when a user uploads a file with the same name of a pre-existing file it appends a sequence number to the file name and keeps both files.

For instance, if the file being loaded is “dailytrackingnumbers.csv” and is uploaded the first time. Then they upload “dailytrackingnumber.csv” a second time. Rather than overwriting the original file gravity forms uploads it to the SFTP location as dailytrackingnumber1.csv. The third time it’s uploaded it’s renamed “dailytrackingnumber2.csv” and so on.

I need a way to have gravity form to replace / overwrite a pre-existing file, rather than renaming and keeping both.

Is this a scenario where the user uploading files is known/consistent and logged in?

I could see an approach working whereby:

  • Set the Form Settings to require the user to be logged in to access the form
  • Use a Gravity Flow User Input Step with either the Save Progress setting turned on, or a radio button the user defines “Are they done sending updated copies of this file?” as Yes/No values.
  • Move your custom code to SFTP, likely hooked on gform_after_submission now, into a custom step type.
  • Using the Conditional Logic and Next Step settings on each, you could create a loop to continue letting them modify (and SFTP update) the file until they are done.
  • In this case, they are deleting the existing file and if they upload new it will have the correct filename.

Regards,
Jamie

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