check for / in the image name and 403 if its there
[quickshow.git] / show.php
1 <?php
2
3 /* This is a very simple app
4  * - you give it a directory where it'll look for jpg's and it'll give a quick index
5  * of them along with clickable links to see the full thing
6  */
7
8 #$show_dir = "/export/data/Pictures/showdir";
9 $show_dir = "/home/paulr/lithium/data/Pictures/show";
10 $n_per_line = 4;
11 $this_url = "http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
12
13
14 if(isset($_REQUEST["showpic"])) {
15         // show the pic requested...
16         if(preg_match("/.*\/+.*/", $_REQUEST["showpic"])) {
17                 header("Status: 403 i dont think so");
18                 error_log("throwing 403");
19                 return;
20         }
21         
22         $afile = "$show_dir/".$_REQUEST["showpic"];
23         if(file_exists($afile)) {
24                 header('Content-Type: image/jpeg');
25                 echo file_get_contents($afile);
26         } else {
27                 header("Status: 404 Not Found");
28         }
29 } else if(isset($_REQUEST["showtmp"])) {
30         // nothing yet
31         if(preg_match("/.*\/+.*/", $_REQUEST["showtmp"])) {
32                 error_log("throwing 403");
33                 header("Status: 403 i dont think so");
34                 return;
35         }
36         $afile = "$show_dir/".$_REQUEST["showtmp"];
37         if(file_exists($afile)) {
38                 header('Content-Type: image/jpeg');
39                 $src = imagecreatefromjpeg($afile);
40                 list($width, $height) = getimagesize($afile);
41                 
42                 if($width > $height) {
43                         $nw = 200;
44                         $nh = (int)($height/($width/200));
45                 } else {
46                         $nh = 200;
47                         $nw = (int)($width/($height/200));
48                         
49                 }
50                 
51                 /*
52                  * 2000
53                  * 1800
54                  * $nw = 200
55                  * $mul = $height/$width/200
56                  */
57                 
58                 error_log("neww = $nw, $nh");
59                 $thumb = imagecreatetruecolor($nw, $nh);
60                 
61                 imagecopyresized($thumb, $src, 0, 0, 0, 0, $nw, $nh, $width, $height);
62                 imagejpeg($thumb);
63         } else {
64                 header("Status: 404 Not Found");
65         }
66         return;
67 } else {
68         
69         // show a grid of images
70         ?>
71 <html>
72 <body>
73 <h1>Temp Show</h1>
74 <table>
75 <?php
76
77         // echo "<pre>";
78         // print_r($_SERVER);
79         //echo "</pre>";
80         $i = 0;
81
82         $dh = opendir($show_dir);
83         while (($file = readdir($dh)) !== false) {
84                 if(preg_match("/.*\.[jJ][pP][gG]$/", $file)) {
85                         if($i == 0) {
86                                 echo "<tr>";
87                         }
88                         
89                         echo "<td><a href=\"$this_url?showpic=$file\"><img src=\"$this_url?showtmp=$file\"></a></td>";
90                         
91                         if($i == ($n_per_line-1)) {
92                                 echo "</tr>";
93                                 $i = 0;
94                         } else {
95                                 $i++;
96                         }
97                 }
98         }
99                 
100
101 ?>
102 </table>
103 </body>
104 </html>
105 <?php
106         
107 }
108 ?>