Try with this:
function get_roles_that_cant($capability) {
global $wp_roles;
if ( !isset( $wp_roles ) ) $wp_roles = new WP_Roles();
$available_roles_names = $wp_roles->get_names();//we get all roles names
$available_roles_capable = array();
foreach ($available_roles_names as $role_key => $role_name) { //we iterate all the names
$role_object = get_role( $role_key );//we get the Role Object
$array_of_capabilities = $role_object->capabilities;//we get the array of capabilities for this role
if(!isset($array_of_capabilities[$capability]) || $array_of_capabilities[$capability] == 0){ //we check if the upload_files capability is present, and if its present check if its 0 (FALSE in Php)
$available_roles_capable[$role_key] = $role_name; //we populate the array of capable roles
}
}
return $available_roles_capable;
}
i took you function and add the logic to get the rol object and get all the capabilities for that object and check if the rol has that capability, also i made it general so you can send which capability you want to check, use it like this:
get_roles_that_cant('upload_files');
it will return an array like this:
Array
(
[contributor] => Contributor
[subscriber] => Subscriber
)
so you can make your dropdown values using the $key
of the array and the option string using the $value
of the array.