From 8c7fbcd7d4510300197bb8817dab7b9d3834774f Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Fri, 1 Mar 2013 16:20:51 +0000 Subject: [PATCH] Fallback for finfo_open Detect if the finfo_open function is available and if not, grab the file extension and compare against an array to work out accepted text based and image based file types to know wether to open in editor or pop open as an image --- lib/file-control.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/file-control.php b/lib/file-control.php index a129951..9cc3b6f 100644 --- a/lib/file-control.php +++ b/lib/file-control.php @@ -22,14 +22,22 @@ if ($_GET['action']=="load") { if (file_exists($file)) { // Determine what to do based on mime type - $finfo = finfo_open(FILEINFO_MIME_TYPE); - if (strpos(finfo_file($finfo, $file),"text")===0 || strpos(finfo_file($finfo, $file),"empty")!==false) { + if (function_exists('finfo_open')) { + $finfoMIME = finfo_open(FILEINFO_MIME_TYPE); + $finfo = finfo_file($finfoMIME, $file); + finfo_close($finfoMIME); + } else { + $fileExt = pathinfo($file, PATHINFO_EXTENSION); + if (array_search($fileExt,array("coffee","css","htm","html","js","less","php","rb","ruby","txt","xml"))!==false) {$finfo = "text";}; + if (array_search($fileExt,array("gif","jpg","jpeg","png"))!==false) {$finfo = "image";}; + } + if (strpos($finfo,"text")===0 || strpos($finfo,"empty")!==false) { echo ''; $loadedFile = file_get_contents($file); echo '","",str_replace("&","&",$loadedFile)).''; - } else if (strpos(finfo_file($finfo, $file),"image")===0) { + } else if (strpos($finfo,"image")===0) { echo ''; } else { echo ''; @@ -37,7 +45,7 @@ if ($_GET['action']=="load") { } else { echo ''; } - finfo_close($finfo); + }; // If we're due to add a new folder...