Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kellenmace/46018fa445c2ceab7d0283fab4858de2 to your computer and use it in GitHub Desktop.
Save kellenmace/46018fa445c2ceab7d0283fab4858de2 to your computer and use it in GitHub Desktop.
Get File Type by URL for a Remote File in WordPress
<?php
/**
* Get the file mime type for a file by its URL.
*
* @param $url The URL to the file.
* @return The file mime type or empty string on failure.
*/
function km_get_file_type_by_url( $url ) {
$response = wp_remote_get( $url );
return wp_remote_retrieve_header( $response, 'content-type' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment