I don’t know the URL of an extension-less image to test this but I’d think that the server would have to pass a content-type
header. If that is the case, you should be able to look at $get['headers']['content-type']
, find out what kind of image it is, and tack the appropriate extension onto $image_file_name
before sending it to wp_upload_bits
.
You’ve already retrieved the information. Take a look at var_dump($get)
, so the idea is to do something like this:
$get = wp_remote_get($image_file_name);
$ending = file_ending_parsing_function($get['headers']['content-type']);
$mirror = wp_upload_bits(basename($image_file_name.$ending), '', wp_remote_retrieve_body($get));
wp_remote_retrieve_body
just grabs information already present in $get
, retrieved by wp_remote_get
, so you aren’t faced with downloading a file that doesn’t exist and I ran a test to confirm that the first parameter of wp_upload_bits
can be anything you choose so long as the extensions match. In fact, tentative testing suggests that it just needs to have an extension. I was able to upload a .jpg
and rename it to a .gif
extension without manipulating the file at all.