^ the user needs to have the correct rights for example
function add_theme_caps() {
$role = get_role( 'contributor' );
$role->add_cap( 'upload_files' );
}
add_action( 'admin_init', 'add_theme_caps');
If you want to add contributors and above to be able to upload_files, change that to subscriber if you want