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

Learn More

How to get info about binary data in a string with finfo_buffer() [fileinfo]

47 Runs 508 Views 173 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

<?php

/**
 * Fileinfo module
 * get info about a string buffer with finfo_buffer()
 */

// open the magic database(if not second parameter is given the MAGIC evironment variable is used or
//if this is not set either then PHP's bundled magic database will be used.)
$finfo = finfo_open(FILEINFO_MIME);

echo '<center>';
if ($finfo) {
    echo '<div style="background-color:green;padding:10px;color:#fff;font-size:16px;">';
    //getting the conent of a website into a string buffer
    $buffer = file_get_contents('http://example.com');
    echo 'The string buffer returned from <b>file_get_contents(\'http://example.com\')</b>
    has the following type:<br /><b>';
    echo finfo_buffer($finfo,$buffer,FILEINFO_MIME); 
    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 */
finfo_close($finfo);
?>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).