I think, you can not exactly determine, but you can assume one with header data.
$headers = wp_get_http_headers( $url );
$mime_type = $headers['content-type'];
$ext="";
foreach ( wp_get_mime_types() as $exts => $mime ) {
if ( $mime == $mime_type ) {
$ext = $exts;
break;
}
}
Now in the $ext
variable, it could be multiple extensions that have been matched, and there’s no way to determine which one the image actually have. But, you could try the first one.
if( $ext ){
$exts = explode('|', $ext);
$ext = $exts[0];
}
Related Posts:
- Image Upload from URL
- Each custom image size in custom upload directory?
- Uploaded images don’t show in Media Library if there are special characters in IPTC Keywords
- Rename files on upload
- Saving the pre-sanitized filename of an attachment as the Title or Caption
- How to copy and paste a picture found on the web to wordpress easily
- Get attachment ID of author_meta image – Attachment Metadata
- Alter media caption/description conflict in WordPress?
- Frontend image uploading from edit profile page. (goldenapples)
- How to Display an Image Uploaded through a Meta Box in a Template?
- HTTP Error when trying to upload image
- Rename attachments during upload
- How to add a media with PHP
- When Uploading JPEGs, Does WordPress Compress the Original Image?
- Uploading images: ‘ø’ get replaced with ‘ø’
- SSL: How to make customizer images Protocol Relative in WordPress?
- Insert image in comment reply
- media_sideload_image with rewritten urls?
- How to order images in a post in WordPress 3.3?
- How to set a contact forms total size limit
- Change WordPress Media Manager
- All Images on wordpress site broken
- Multiple images with Media Uploader on front-end
- How to keep WP from recompressing Full Size images
- Faster way to put images into a blog post by using Add Media dialog
- Handling image uploads without thickbox
- Alter the image, before save, of a particular image size
- WordPress automatically downscaled images larger that original
- Loose images in uploads folder
- Force minimum image size and aspect ratio when uploading images
- Missing a temporary folder.error when image is uploaded in admin Set temporary Directory – WordPress 5.2.2
- WP fails to upload files to media library, /wp-admin/async-upload.php 403 forbidden
- Add a background image for Custom Post Type archives page
- Convert uploaded GIF to non animated image automatically
- Is it possible to split Default WP Media directory to multiple Folder/Subdomain?
- Ho to add “Create Slider” option to default “Add Media” popup?
- Show image crop window on image upload
- Images in Media aren’t showing, not broken
- Upload Image using wp_insert_attachment and file url don’t have file extension
- Images uploaded to the media library has strange colors. However, in the edit screen the color is ok
- Uploaded images not displaying in network site
- Change image name during uploading sequentially
- How to limit the number of images displayed in the media window?
- How to get the Gallery form/section just like in Gutenberg block?
- How to set uploaded image as featured image wordpress
- Get images attached to a specific page
- WordPress Creates Unused (Unregistered) Image Sizes
- Images don’t update after being edited
- Is there a way in WordPress to convert images to WebP without a plugin?
- Some Images Disappeared from Media Library?
- after migration, newly uploaded images won’t show up
- Disable image rename on upload
- HTTP error when uploading an image
- Image upload error?
- How can i identify media uploaded to my website that is not being used anywhere anymore?
- How to add “alt” attribute for image during upload at WP front-end?
- How to use getimagesize() of image upload?
- Upload images – Theme options
- How to change image’s author via a function when using GravityForms uploader? [closed]
- image URL changed in wordpress
- Alter the image used for a user who has not uploaded a custom image yet
- Allow users to upload multiple images to their profile
- image upload/edit is broken: “Image data does not exist. Please re-upload the image.”
- Serving Images from subdomain in wordpress
- User uploads image as “Featured Image” but WordPress resizes it?
- WordPress append -1 to the image name
- Recreate the upload folder from a website without having access to the backend/cpanel/filezilla directly from the website
- How to increase media image scale limit?
- media_handle_upload() with 1 image under 1Mb chokes my server and returns timeout error
- WordPress PHP custom function is causing 500 Internal Server Error Connection Timeout
- Could creation of various image sizes cause slow form submission response?
- Can’t upload Images to WordPress – Error 500 Response
- Updated wordpress missing image upload area
- WordPress 4.4.2 upload give error, can’t write is upper directory allowed to be written
- How to trigger “wp_handle_upload_prefilter” filter when uploading an image programatically?
- Change wordpress default upload path to another domain
- Broken images in media library
- Images are not getting uploaded
- Run command to optimize images after they get uploaded to WordPress
- Where to add my code to auto attach images to existing products
- WAMP install acts different than live install when uploading images
- Set WordPress to Create different images format later, not during upload
- How can I hook and edit on the fly an image uploaded
- Assigning image to Post-Type won’t work anymore: exceeded time?
- The most of the images don’t appear, although URLs are correct
- Assign one featured image to multiple posts?
- Add two images with Sweet Testimonials
- Upload button in metabox not working
- Import existing image as a single post
- Upload unnattached image from frontend
- My image rotate 90 degree
- How do I change a Themes Header Image?
- Media Library is not loading on grid view in admin panel
- Blurry Images WordPress 5.8.1
- Media upload error
- wp_handle_upload Image sizes
- Can’t manage to display an uploaded picture (uploaded from a custom button) in the front end
- What does WordPress media uploader do to image files on upload?
- Can’t upload svg files in WordPress
- Random images from uploads folder and subfolder