There is special wp_upload_bits()
function to upload the content to the ‘uploads’ directory. Also, there is no such directory as /wp-includes/upload/
.
The code was not tested!
<?php
$video_id = 'xxxxxxxxxxxxx';
$thumbnail_types = array(
'0',
'1',
'2',
'3',
'default',
'sddefault',
'mqdefault',
'hqdefault',
'maxresdefault',
);
foreach( $thumbnail_types as $type ) {
$file_name = $type . '.jpg';
$youtube_thumb_url="http://img.youtube.com/vi/" . $video_id . "https://wordpress.stackexchange.com/" . $file_name;
$thumbnail_file = file_get_contents( $youtube_thumb_url );
// Where the magic happens
$uploaded_file = wp_upload_bits( $file_name, null, $thumbnail_file );
// check the result
echo '<pre>';
print_r( $uploaded_file ) ; // path, URL, file type and error message
echo '</pre>';
}