Speed up development with full-stack environments for every branch.

Learn More

How to get info about a file with finfo_file() [fileinfo]

118 Runs 992 Views 319 Copies


gtsolutions 373

published 4 years ago


 * Fileinfo module
 * get info about a file with finfo_file()
// open the magic database
$finfo = finfo_open(FILEINFO_MIME, "/usr/share/misc/magic");

echo '<center>';
if ($finfo) {
    echo '<div style="background-color:green;padding:10px;color:#fff;font-size:16px;">';
    /* get mime-type for a specific file */
    $filename = "sample.txt";
    echo'Here are the info about <b><i>' . $filename . '</i></b><br /><b>';
    echo finfo_file($finfo, $filename);
    echo '</b></div>';
} else {
    echo '<div style="background-color:red;padding:10px;color:#fff;font-size:16px;">';
    echo 'Could not open magic database';
    echo '</div>';
echo '</center>';

/* close connection */
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).