857a3203300ba9a895e7c8d603dbbcc8d607a75e
[Pman.Ftp] / View.php
1 <?php
2
3 require_once 'Pman/Ftp/List.php';
4
5 class Pman_Ftp_View extends Pman_Ftp_List
6 {
7     //getAuth = covered by list
8     
9     function get($v)
10     {
11         
12         $ext = pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION);
13         $v .= '.'. $ext;
14         
15         $v = urldecode($v);
16         $fp = $this->clean($v);
17         
18         require_once 'File/MimeType.php';
19         $fm = new File_MimeType();
20         $mt = $fm->fromExt($ext);
21         
22         if (!isset($_REQUEST['html'])) {
23             header("Content-type: $mt");
24             $fh = fopen($fp,'r');
25             fpassthru($fh);
26             fclose($fh);
27             exit;
28         }
29         
30         
31         switch($mt) {
32             case 'text/plain':
33             case 'application/xml':
34                 $fc = file_get_contents($fp);
35                 $matches = array();
36                 if (preg_match('#^\s*<\?xml.*encoding="([^"]+)"#mi', $fc, $matches)) {
37                     $fc = iconv($matches[1], "UTF8//IGNORE", $fc);
38                 }
39
40             
41             
42                 echo '<PRE>'. htmlspecialchars($fc) . '</PRE>';
43                 exit;
44                 
45             case 'image/jpeg':
46                 echo '<img src="'. $this->baseURL.'/Ftp/View/'.$v . '">';
47                 exit;
48             
49             
50             default:
51                 // handle download.
52                 require_once 'File/Convert.php';
53                 $f = new File_Convert($fp, $mt);
54                 $f->convert("application/pdf"); // does no conversion (as it's the same.
55
56                 $f->serve('attachment');
57                 
58             
59             
60             
61                 die("Can not handle " . $mt . " yet");
62         }
63         
64         
65         
66         var_dump($fp);
67         
68         die("done");
69         exit;
70     }
71     
72     
73     
74     
75 }