Back to index

php5  5.3.10
fileinfo.php
Go to the documentation of this file.
00001 <?php
00002 if(!extension_loaded('fileinfo')) {
00003        dl('fileinfo.' . PHP_SHLIB_SUFFIX);
00004 }
00005 if(!extension_loaded('fileinfo')) {
00006        die("fileinfo extension is not avaliable, please compile it.\n");
00007 }
00008 
00009 // normal operation
00010 $res = finfo_open(FILEINFO_MIME); /* return mime type ala mimetype extension */
00011 $files = glob("*");
00012 foreach ($files as $file) {
00013        echo finfo_file($res, $file) . "\n";
00014 }
00015 finfo_close($res);
00016 
00017 // OO mode
00018 /*
00019  * FILEINFO_PRESERVE_ATIME - if possible preserve the original access time
00020  * FILEINFO_SYMLINK - follow symlinks
00021  * FILEINFO_DEVICES - look at the contents of blocks or character special devices
00022  * FILEINFO_COMPRESS - decompress compressed files
00023  */
00024 $fi = new finfo(FILEINFO_PRESERVE_ATIME|FILEINFO_SYMLINK|FILEINFO_DEVICES|FILEINFO_COMPRESS);
00025 $files = glob("*");
00026 foreach ($files as $file) {
00027         echo $fi->buffer(file_get_contents($file)) . "\n";
00028 }
00029 ?>