source: trunk/action.php @ 1552

Last change on this file since 1552 was 1552, checked in by rub, 18 years ago

Resolved Issue ID 0000544:

o Error on download HD picture

Merge branch-1_6 1550:1551 into BSF

  • Property svn:keywords set to Date Author Rev URL
File size: 3.3 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: 2006-09-20 21:24:34 +0000 (Wed, 20 Sep 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Rev: 1552 $
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
62  // Looking at the safe_mode configuration for execution time
63  if (ini_get('safe_mode') == 0)
64  {
65    @set_time_limit(0);
66  }
67
68  @readfile("$filename") or die("File not found.");
69}
70
71//--------------------------------------------------------- download big picture
72if ( isset( $_GET['dwn'] ) )
73{
74//TODO : verify the path begins with something in galleries_url and that user has access rights to the picture
75// in order to avoid hacking atempts by forged url
76  if (preg_match('/\.\./',$_GET['dwn'])) {
77    die('Hacking attempt!');
78  }
79  force_download($_GET['dwn']);
80}
81
82?>
Note: See TracBrowser for help on using the repository browser.