PHP code example of karwana / mime

1. Go to this page and download the library: Download karwana/mime 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/ */

    

karwana / mime example snippets


use Karwana\Mime;

$extension = Mime::guessExtension($_FILES['my_file']['tmp_name'], $_FILES['my_file']['name']);

move_uploaded_file($_FILES['my_file']['tmp_name'], 'uploads/' . Uuid::v4() . '.' . $extension);

header('Content-Type: ' . Mime::guessType($my_file));
header('Content-Length: ' . filesize($my_file));
readfile($my_file);

$my_file = 'path/to/extensionless_file';

rename($my_file, $my_file . '.' . Mime::guessExtension($my_file));