I'm currently developing a plugin for my page. The goal is to upload a custom profile image from a user page. Now I want to store each image under a pre-defined name. Sadly I've no plan how I can set a custom name for a file during the file upload with the WordPress function wp_upload_bits()
:
$filename = $_FILES['file']['name'];
$uploaded_bits = wp_upload_bits(
$filename,
null,
file_get_contents( $_FILES['file']['tmp_name'] )
);
Currently when I upload for example an image with the name yolo.png
, the name stays yolo.png
.
Now I want to define the new name this way:
$filename = 'profile-image-' . get_current_user_id();
But this can't work because the $_FILES['file']['name']
is the temporarily saved file on my server and this is yolo.png
. So do you have any idea how I can reach my goal?