I am using the following code to retrieve images from the web:
$get = wp_remote_get($image_file_name); $mirror = wp_upload_bits(basename($image_file_name), '', wp_remote_retrieve_body($get));
This code works just fine with all sorts of images except when images have no extension. For example, if image file name was:
then running the above code would be ok. However, the link
would give the following error:
Array ( [error] => Invalid file type )
After further investigation, it looks like wp_upload_bits has the following code in it:
$wp_filetype = wp_check_filetype( $name ); if ( ! $wp_filetype['ext'] && ! current_user_can( 'unfiltered_upload' ) ) return array( 'error' => __( 'Invalid file type' ) );
And it seems that it is checking if an extension actually exists, and if not, then there is an error.
So my question is how do I work around this to download images that do not have extensions?