Merge pull request #8 from radiocontrolled/0004872
[atutor.git] / get_course_icon.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* Inclusive Design Institute                                           */
7 /* http://atutor.ca                                                     */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12 // $Id: get_profile_img.php 6979 2007-06-20 17:35:02Z greg$
13 define('AT_INCLUDE_PATH', 'include/');
14 @ob_end_clean();
15 header("Content-Encoding: none");
16
17 $_user_location = 'public';
18
19 require(AT_INCLUDE_PATH . 'vitals.inc.php');
20
21
22 require(AT_INCLUDE_PATH . 'lib/mime.inc.php');
23
24 $id = intval($_GET['id']);
25 $sql="SELECT icon from ".TABLE_PREFIX."courses WHERE course_id='$id'";
26 $result = mysql_query($sql, $db);
27 while($row=mysql_fetch_assoc($result)){
28         $filename = $row['icon'];
29 }
30
31 $file = AT_CONTENT_DIR .$id.'/custom_icons/'.$filename;
32
33 $extensions = array('gif', 'jpg', 'png');
34 $pathinfo = pathinfo($file);
35 $ext = strtolower($pathinfo['extension']);
36 if ($ext == '') {
37         $ext = 'application/octet-stream';
38 } else {
39         $ext = $mime[$ext][0];
40 }
41
42 $real = realpath($file);
43
44 if (file_exists($real) && (substr($real, 0, strlen(AT_CONTENT_DIR)) == AT_CONTENT_DIR)) {
45
46         header('Content-Disposition: filename="'.$size.$id.'.'.$pathinfo['extension'].'"');
47         
48         /**
49          * although we can check if mod_xsendfile is installed in apache2
50          * we can't actually check if it's enabled. also, we can't check if
51          * it's enabled and installed in lighty, so instead we send the 
52          * header anyway, if it works then the line after it will not
53          * execute. if it doesn't work, then the line after it will replace
54          * it so that the full server path is not exposed.
55          *
56          * x-sendfile is supported in apache2 and lighttpd 1.5+ (previously
57          * named x-send-file in lighttpd 1.4)
58          */
59         header('x-Sendfile: '.$real);
60         header('x-Sendfile: ', TRUE); // if we get here then it didn't work
61
62         header('Content-Type: '.$ext);
63
64         @readfile($real);
65         exit;
66 } else {
67         header('HTTP/1.1 404 Not Found', TRUE);
68         exit;
69 }
70
71 ?>