source: trunk/action.php @ 1133

Last change on this file since 1133 was 986, checked in by chrisaga, 19 years ago
  • svn : set svn keywords for action.php
  • Property svn:keywords set to Date Author Rev URL
File size: 3.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $URL: trunk/action.php $
9// | last update   : $Date: 2005-12-19 19:18:48 +0000 (Mon, 19 Dec 2005) $
10// | last modifier : $Author: chrisaga $
11// | revision      : $Rev: 986 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28function force_download ($filename)
29{
30//TODO : messages in "lang"
31  $filename = realpath($filename);
32
33  $file_extension = strtolower(substr(strrchr($filename,"."),1));
34
35  switch ($file_extension) {
36      case "jpe": case "jpeg":
37      case "jpg": $ctype="image/jpg"; break;
38      case "png": $ctype="image/png"; break;
39      case "gif": $ctype="image/gif"; break;
40      case "pdf": $ctype="application/pdf"; break;
41      case "zip": $ctype="application/zip"; break;
42      case "php": 
43        // never allow download of php scripts to protect our conf files
44        die('Hacking attempt!'); break;
45      default: $ctype="application/octet-stream";
46  }
47
48  if (!file_exists($filename)) {
49      die("NO FILE HERE");
50  }
51
52  header("Pragma: public");
53  header("Expires: 0");
54  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
55  header("Cache-Control: private",false);
56  header("Content-Type: $ctype");
57  header("Content-Disposition: attachment; filename=\""
58         .basename($filename)."\";");
59  header("Content-Transfer-Encoding: binary");
60  header("Content-Length: ".@filesize($filename));
61  set_time_limit(0);
62  @readfile("$filename") or die("File not found.");
63}
64
65//--------------------------------------------------------- download big picture
66if ( isset( $_GET['dwn'] ) )
67{
68//TODO : verify the path begins with './gallerie' and doesn't contains any '..'
69// in order to avoid hacking atempts
70  force_download($_GET['dwn']);
71}
72
73?>
Note: See TracBrowser for help on using the repository browser.