Home Forums Add-ons Repeater Field Renaming a photo upon upload


Renaming a photo upon upload

  • Is it possible to rename a photo when it is uploaded to a slider?

    What I have is a repeater that is an image slider and I have a text field for a stock number. What I’m wondering is if there is a way to rename the photos that are upload uploaded to the slider to have “stocknumber_img_#”?

  • It is possible to change the file name of an uploaded file during the upload in WP, you can do a search for this and find several solutions, however, it’s not possible to do what you’re looking for. The reason is that the field with the stock number won’t be available until after the image is already uploaded and saved to the uploads folder. When you add an image in ACF the image is uploaded and then then actual value of the field is the image ID that was uploaded.

    Giving this some thought, you could rename the file after the upload once the post is submitted. Well, not really rename it exactly, more like replace it. You could create an acf/save_post filter and in this filter

    1. Get the information about the image that was uploaded
    2. use this information to insert a new image with the altered file name using
    3. Update the ACF field with the ID of the new image
    4. Delete the first image with
  • I am looking to do something similar, but simpler. I have a front-end form that allows the user to upload an image attachment to their account (separate from their profile pic). So the form would save to post_id of ‘user_123’ (for user ID 123).

    Do I need to use this technique in order for the image upload to work, or is it sufficient to have an image field in the form group used in the acf_form?

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Renaming a photo upon upload’ is closed to new replies.