View.php
authorAlan Knowles <alan@akbkhome.com>
Mon, 12 Apr 2010 09:48:43 +0000 (17:48 +0800)
committerAlan Knowles <alan@akbkhome.com>
Mon, 12 Apr 2010 09:48:43 +0000 (17:48 +0800)
View.php [new file with mode: 0644]

diff --git a/View.php b/View.php
new file mode 100644 (file)
index 0000000..da34b34
--- /dev/null
+++ b/View.php
@@ -0,0 +1,65 @@
+<?php
+
+require_once 'Pman/Ftp/List.php';
+
+class Pman_Ftp_View extends Pman_Ftp_List
+{
+    //getAuth = covered by list
+    
+    function get($v)
+    {
+        
+        $ext = pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION);
+        $v .= '.'. $ext;
+        
+        $v = urldecode($v);
+        $fp = $this->clean($v);
+        
+        require_once 'File/MimeType.php';
+        $fm = new File_MimeType();
+        $mt = $fm->fromExt($ext);
+        
+        if (!isset($_REQUEST['html'])) {
+            header("Content-type: $mt");
+            $fh = fopen($fp,'r');
+            fpassthru($fh);
+            fclose($fh);
+            exit;
+        }
+        
+        
+        switch($mt) {
+            case 'text/plain':
+            case 'application/xml':
+                $fc = file_get_contents($fp);
+                $matches = array();
+                if (preg_match('#^\s*<\?xml.*encoding="([^"]+)"#mi', $fc, $matches)) {
+                    $fc = iconv($matches[1], "UTF8//IGNORE", $fc);
+                }
+
+            
+            
+                echo '<PRE>'. htmlspecialchars($fc) . '</PRE>';
+                exit;
+                
+            case 'image/jpeg':
+                echo '<img src="'. $this->baseURL.'/Ftp/View/'.$v . '">';
+                exit;
+            
+            
+            default: 
+                die("Can not handle " . $mt . " yet");
+        }
+        
+        
+        
+        var_dump($fp);
+        
+        die("done");
+        exit;
+    }
+    
+    
+    
+    
+}
\ No newline at end of file