- file_get_contents: documentation ( source)
- pathinfo: documentation ( source)
- var_dump: documentation ( source)
- basename: documentation ( source)
<?php
$finfo = new finfo(FILEINFO_MIME_TYPE);
$postMimeType = $finfo->buffer(file_get_contents('http://google.com'));
// If the URL has the file extension included, this will find it
$fileExtension = pathinfo('http://google.com', PATHINFO_EXTENSION);
// Otherwise, get file extension from the MIME type
// This is necessary for image thumbnails to display correctly in the WordPress dashboard media section
if ($fileExtension === '') {
$fileExtension = basename($postMimeType);
$filename = $filename . '.' . $fileExtension;
}
var_dump($fileExtension);