Hello, I want to do this so that people outside the page do not guess the names of my users’ private files.
When uploading files via Xprofile Custom Field Types, I want it to be renamed to some random name.
For example: I upload a file called “door.pdf” and I want it to be saved as “3685214.pdf ” when uploading.I have been using the Xprofile Custom Field Types plugin and I love it and thank you.
I hope some help please
Hi Oscar,
Welcome to BuddyDev support forums.The files upload by Xprofile custom field types are public. Please do not treat them as private.
It is still possible to hash/encrypt file name.
Yo may want to try this one
/** * Encrypts file name using md5 * * @param array $file file info. * * @return array */ function buddydev_cusotm_encrypt_file_name( $file ) { $info = pathinfo( $file['name'] ); $ext = empty( $info['extension'] ) ? '' : '.' . $info['extension']; $name = basename( $file['name'], $ext ); $new_file_name = md5( $name ); // limit file name to 12 characters. comment if you don't want to limit. $new_file_name = substr( $new_file_name, 0, 12 ); // update file name. $file['name'] = $new_file_name . $ext; return $file; } add_filter( 'wp_handle_upload_prefilter', 'buddydev_cusotm_encrypt_file_name' );
Please do note that it will encrypt the file name for all files uploaded via WordPress and not just ours. In next release, I will put an extra hook to allow us to it selectively.
Regards
BrajeshThank you very much for your prompt response, I understand what you are saying.
I’ll put it to the test, but if I’m interested in encrypting the file name only for files uploaded by Xprofile Custom Field Types. I will be waiting for a soon update. Thanks for your plugins they are the best
Thank you Oscar.
Please do let me know if it worked or not?Regards
Brajesh
You must be logged in to reply to this topic.