1. Go to this page and download the library: Download dfridrich/php-mime-type library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dfridrich / php-mime-type example snippets
// from string, can be used on non-existing files
echo \Defr\PhpMimeType\MimeType::get('index.php'); // outputs text/html
// from SplFileInfo
echo \Defr\PhpMimeType\MimeType::get(new \SplFileInfo('Video.avi')); // outputs application/octet-stream
// from SplFileObject
echo \Defr\PhpMimeType\MimeType::get(new \SplFileObject('Image.JPEG')); // outputs image/jpeg
// from string
echo \Defr\PhpMimeType\MimeType::get('someStrange.extension'); // outputs application/octet-stream
// Multiple files
$files = ['index.php', new \SplFileInfo('Video.avi'), new \SplFileObject('example.php')];
/** @var \Defr\PhpMimeType\MimeTypeInfo[] $mimeTypes */
$mimeTypes = \Defr\PhpMimeType\MimeType::multiple($files);
foreach ($mimeTypes as $mimeType) {
echo sprintf('File "%s" is mime type "%s"', $mimeType->getFileName(), $mimeType->getMimeType()).'<br>';
}
// Guess FontAwesome icon
echo \Defr\PhpMimeType\MimeType::getFontAwesomeIcon('test.pdf'); // fa fa-file-pdf-o
// ...with fixed width icon
echo \Defr\PhpMimeType\MimeType::getFontAwesomeIcon('test.pdf', true); // fa fa-file-pdf-o fa-fw
// Return response to download this file as attachment (default)
$response = \Defr\PhpMimeType\MimeType::response(__FILE__);
$response->send();
// Return response to download this file inline
$response = \Defr\PhpMimeType\MimeType::response(__FILE__, \Symfony\Component\HttpFoundation\ResponseHeaderBag::DISPOSITION_INLINE);
$response->send();
// You can use FileAsResponse object too (and own file name)
$response = \Defr\PhpMimeType\FileAsResponse::get(__FILE__, null, "my-own-file-name.txt");
$response->send();
// Or directly send it to browser
$response = \Defr\PhpMimeType\FileAsResponse::send(__FILE__);
sh
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.