media_sideload_image
WordPress has a media_sideload_image function. It is used to upload an image and attach it to a media library.
I accept image urls as follows:
h ** p: //s.wordpress.org/style/images/wp-header-logo.png
Rewritten URLs
Some URLs on the Internet are rewritten, for example:
http://placekitten.com/100/100
Error message:
"Unfortunately, this file type is not allowed for security reasons."
The file type is the correct jpg file, but the file extension is missing.
Adding additional MIME types does not work, in my case
I tried this function, but it does not help me, because it is a file extension that is not installed.
add_filter('upload_mimes', 'add_custom_upload_mimes'); function add_custom_upload_mimes($existing_mimes){ $existing_mimes['jpeg'] = 'image/jpeg'; return $existing_mimes; }
Question
How to upload the h ** p: //placekitten.com/100/100 URL using media_sideload_image or similarly to attach an image to a media library?
source share