From 75e9f916ec1a9dab965c80172f2d0dfb05e52880 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Thu, 25 Oct 2012 12:38:36 +0100 Subject: [PATCH] Opening file by mime type now Detect if it's text based, image based or other and open as appropriate (text = editor, image = media preview, other = new window) --- lib/file-control.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/file-control.php b/lib/file-control.php index 88113e5..8a9046d 100644 --- a/lib/file-control.php +++ b/lib/file-control.php @@ -20,12 +20,9 @@ $fileName = basename($file); if ($_GET['action']=="load") { echo ''; - // Determine what to do based on filename - // Everything is opened as text in the editor unless specified otherwise - $fileType="text"; - if (strpos($fileName,".jpg")>0||strpos($fileName,".jpeg")>0||strpos($fileName,".gif")>0||strpos($fileName,".png")>0) {$fileType="image";}; - - if ($fileType=="text") { + // Determine what to do based on mime type + $finfo = finfo_open(FILEINFO_MIME_TYPE); + if (strpos(finfo_file($finfo, $file),"text")===0) { if (file_exists($file)) { echo ''; } - }; - - if ($fileType=="image") { + } else if (strpos(finfo_file($finfo, $file),"image")===0) { echo ''; + } else { + echo ''; }; + finfo_close($finfo); }; // If we're due to add a new folder...