Home › Forums › ACF PRO › Rename files upon uploading › Reply To: Rename files upon uploading
If I insert the code from add_attachment to after_save_post as below, then I end up with ‘double images’ because the image does gets renamed, but in a new file. It doesn’t rename the current file.
The new files names are linked to the post, the original file names are not and thus they can not be deleted with a function, otherwise the issue would be solved.
if ( false == $image_is_approved ) {
$file = $this->get_location_of_attachment_file( $stored_profile_pic );
if ( false !== $file ) {
$path = pathinfo( $file );
$newfilename = $this->getToken( 10 );
$newfile = $path[ 'dirname' ] . "/" . $newfilename . "." . $path[ 'extension' ];
rename( $file, $newfile );
update_attached_file( $stored_profile_pic, $newfile );
}
global $wpdb;
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.