-
Notifications
You must be signed in to change notification settings - Fork 7
/
transfer.php
98 lines (87 loc) · 3.8 KB
/
transfer.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
#Uploads accepts file fragments, identified by a file_id and inserts the file in an appropriate location where it can be retrieved by s3db and linked in a statement
#Helena F Deus, Dec 1, 2006
ini_set('display_errors',0);
if($_REQUEST['su3d']) {
ini_set('display_errors',1);
}
if(file_exists('config.inc.php')) {
include('config.inc.php');
} else {
Header('Location: index.php');
exit;
}
$xml = $_REQUEST['file'];
$format=$_REQUEST['format'];
#Determine if XML is a URL or a string
if (ereg('http://.*', $xml)) {
$handle = fopen ($xml, 'rb');
$xml = stream_get_contents($handle);
fclose($handle);
}
$xml = simplexml_load_string($xml); #this will read the xml and output the result on an array
#Get the key, send it to check validity, if key is missing check for filekey
$key = $xml->key;
if ($key == '') { $key = $_REQUEST['key']; }
if ($key != '') {
#Ckeck for filename and generate the filekey
#include_once('core.keyheader.php');
include_once('core.header.php');
#include_once('s3dbcore/transferFile.php');
if(!$_FILES) {echo formatReturn('3','No file to upload.', $_REQUEST['format'],'');
exit;
} elseif($file_id == '') { #If a file_id is not provided, create one
ereg('.*\.([a-zA-Z0-9]*)$', $_FILES['Filedata']['name'], $ext);
$ext = $ext[1];
#if there is no data besides the key, ask for a filename and filesize
$filename = $_FILES['Filedata']['name'];
if($filename == '') { $filename = $xml -> filename; }
$filesize = $_REQUEST['filesize'];
if($filesize == '') { $filesize = $xml -> filesize; }
$filekey = generateAFilekey(compact('filename', 'filesize', 'db', 'user_id'));
#Retrieve the file_id fro mthe filekey
$tmp= get_filekey_data($filekey, $db); $file_id = $tmp['file_id'];
##Now upload the file
#Define the folder where these files will be stored
$folder = $GLOBALS['s3db_info']['server']['db']['uploads_folder'].$GLOBALS['s3db_info']['server']['db']['uploads_file'].'/tmps3db/';
$final = $folder.$file_id.'.'.$ext;
##Copy file from Php tmp directory
$moved = copy($_FILES['Filedata']['tmp_name'], $final);
if($moved) {
##Was a rule_id and item_id provided? If yes, insert it using s3ql, if not, provide the filekey
if($_REQUEST['item_id'] && $_REQUEST['rule_id']) {
$s3ql=compact('user_id','db');
$s3ql['insert']='file';
$s3ql['where']['item_id']=$_REQUEST['item_id'];
$s3ql['where']['rule_id']=$_REQUEST['rule_id'];
$s3ql['where']['filekey']=$filekey;
$s3ql['format']=$_REQUEST['format'];
$done = S3QLaction($s3ql);
echo $done;exit;
} else {
echo formatReturn('0',"This filekey is to be used instead of key for file transfer, it will expire in 24h. Break the file in base64 encoded fragments, replacing the character '+' with it's URL equivalent '%2b'",$format,array('filekey'=>$filekey));
}
} else {
echo formatReturn('2',"Failed to import file",$format,'');
}
}
} else { #if key is empty, check for filekey
$filekey = $xml->filekey;
if($filekey == '') { $filekey = $_REQUEST['filekey']; }
if($filekey!='') {
include_once('core.filekeyheader.php');
#add a form to the page such that it accepts both POST and GET
#echo '<form name="file" method="POST">';
#echo '<input type="hidden" name="query"> <!-- this form is for programming environments that support sending POST -->';
#echo '</form>';
#echo receiveFileFragments(compact('filekey', 'db'));
echo formatReturn('0',receiveFileFragments(compact('filekey', 'db')), $format,'');
exit;
} else {
include_once (S3DB_SERVER_ROOT.'/s3dbcore/callback.php');
include_once (S3DB_SERVER_ROOT.'/s3dbcore/display.php');
echo formatReturn('3',"Filekey is missing.",$format,'');
exit;
}
}
?>