-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetfile.php
65 lines (49 loc) · 1.65 KB
/
getfile.php
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
<?php
@ini_set("display_errors","1");
@ini_set("display_startup_errors","1");
require_once("include/dbcommon.php");
$shortTableName = postvalue("table");
$table = GetTableByShort( $shortTableName );
if( !$table )
exit(0);
$pageName = postvalue("pagename");
$strFilename = postvalue("filename");
$ext = substr( $strFilename, strlen($strFilename) - 4 );
$ctype = getContentTypeByExtension($ext);
$field = postvalue("field");
if( !Security::userHasFieldPermissions( $table, $field, PAGE_LIST, $pageName, false ) )
return;
$pSet = new ProjectSettings( $table, PAGE_LIST, $pageName );
$gQuery = $pSet->getSQLQuery();
if( !$gQuery->HasGroupBy() )
{
// Do not select any fields except current (file) field.
// If query has 'group by' clause then other fields are used in it and we may not simply cut 'em off.
// Just don't do anything in that case.
$gQuery->RemoveAllFieldsExcept( $pSet->getFieldIndex($field) );
}
$_connection = $cman->byTable( $table );
// construct sql
$keysArr = $pSet->getTableKeys();
$keys = array();
foreach( $keysArr as $ind=>$k )
{
$keys[$k] = postvalue("key".($ind + 1));
}
$where = KeyWhere($keys, $table);
if( $pSet->getAdvancedSecurityType() == ADVSECURITY_VIEW_OWN )
{
$where = whereAdd( $where, SecuritySQL("Search") );
}
$sql = $gQuery->gSQLWhere( $where );
$qResult = $_connection->query( $sql );
if( !$qResult || !($data = $qResult->fetchAssoc()) )
return;
$value = $_connection->stripSlashesBinary( $data[$field ] );
header("Content-Type: ".$ctype);
header("Content-Disposition: attachment;Filename=\"".$strFilename."\"");
header("Cache-Control: private");
SendContentLength( strlen_bin($value) );
echoBinary( $value );
return;
?>