Menu

[r11]: / includes / download.php  Maximize  Restore  History

Download this file

76 lines (68 with data), 2.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/*
** Application name: phpCollab
** Last Edit page: 12/01/2005
** Path by root: ../includes/download.php
** Authors: Ceam / Fullo
**
** =============================================================================
**
** phpCollab - Project Managment
**
** -----------------------------------------------------------------------------
** Please refer to license, copyright, and credits in README.TXT
**
** -----------------------------------------------------------------------------
** FILE: download.php
**
** DESC: lib: download files
**
** HISTORY:
** 30/06/2005 - fix for [ 1229004 ] filenames have an extra slash
** -----------------------------------------------------------------------------
** TO-DO:
** =============================================================================
*/
// MIMETypes should be handled using PHP mime.magic once it's out
include("../includes/mimetypes.php");
$filespath="../files";
// construct file path and test whether file exists/is accessible
$name=$fileDetail->fil_name[0];
$project=$fileDetail->fil_project[0];
$task=$fileDetail->fil_task[0];
// take care of subdirectories for files associated with tasks
if ($task == "0")
{
$path = $filespath."/".$project."/".$name;
}
else
{
$path = $filespath."/".$project."/".$task."/".$name;
}
if (!file_exists($path)) { echo "file does not exist:-/"; exit; }
// figure out mimetype, should be done using PHP mime.magic once it's out
$mimetype = $mimetypes[$fileDetail->fil_extension[0]];
// Apache behaviour seems to send text/plain for unknown mimetypes so that's what we do, too
if ($mimetype == "")
{
$mimetype="text/plain";
}
// eval 'mode' parameter for either view or download
if ($mode == "download")
{
header("Content-Length: ".filesize($path));
header("Content-Type: $mimetype");
header("Content-Disposition: attachment; filename=$name");
}
elseif ($mode == "view")
{
header("Content-Length: ".filesize($path));
header("Content-Type: $mimetype");
header("Content-Disposition: inline; filename=$name");
// Apache is sending Last Modified header, so we'll do it, too
$modified=filemtime($path);
header("Last-Modified: ".date("D, j M Y G:i:s T",$modified)); // something like Thu, 03 Oct 2002 18:01:08 GMT
}
# write file as response
readfile($path);
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.