$fileInfo = finfo_open(FILEINFO_MIME_TYPE); // open file info $mime = finfo_file($fileInfo, "/path/to/file"); // get MIME type echo $mime; finfo_close($fileInfo); // close file info
$fileInfo = new SplFileInfo("/path/to/file"); echo "File name: " . $fileInfo->getFilename() . "This example creates a new SplFileInfo object for the file located at "/path/to/file". We can then call methods on the object to get various information about the file, such as its name, size, and type. The Fileinfo extension is part of the PHP standard library, so it does not require any additional packages or libraries.
"; echo "File size: " . $fileInfo->getSize() . "
"; echo "File type: " . $fileInfo->getType() . "
";