# HG changeset patch # User Matti Hamalainen # Date 1416857638 -7200 # Node ID 95c3e0a1058ef784b3601d07c82e51c028a99f87 # Parent 4df1bfd11131413d7356fa2ee2578d93a1dacd78 Add new helper function stProbeFileInfo(). diff -r 4df1bfd11131 -r 95c3e0a1058e msite.inc.php --- a/msite.inc.php Mon Nov 24 21:31:04 2014 +0200 +++ b/msite.inc.php Mon Nov 24 21:33:58 2014 +0200 @@ -988,6 +988,44 @@ } +// +// Probe file type information +// +function stProbeFileInfo($filename) +{ + global $previewFileTypeList; + + // Get file magic info + if (($finfo = finfo_open()) === false) + return stError("Internal error. Failed to initialize finfo()."); + + $sdata = @finfo_file($finfo, $filename, FILEINFO_NONE); + $smime = @finfo_file($finfo, $filename, FILEINFO_MIME_TYPE); + finfo_close($finfo); + + // Did we get anything? + if ($sdata === FALSE || $smime === FALSE) + return stError("Internal error, failed to probe file."); + + // Match through our supported types .. + foreach ($previewFileTypeList as $fid => $fdata) + { + $fdata["id"] = $fid; + + if (isset($fdata["test"])) + { + if (preg_match("/".$fdata["test"]."/", $sdata)) + return $fdata; + } + else + if ($fdata["mime"] == $smime) + return $fdata; + } + + return stError("No matching allowed file type found."); +} + + // Get link helper function function stGetMainPageLink($id, $name, $show = TRUE) {