summaryrefslogtreecommitdiff
blob: d8dd4ecbbae8c2a176cd33e2332ac8380293d390 (plain)
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
<?php
function init_upload(&$S) {
	if (!(isset($_REQUEST['build'], $_REQUEST['key'], $_FILES['file']) && preg_match('/^[a-zA-Z0-9]{6}$/', $_REQUEST['build']) && preg_match('/^[a-zA-Z0-9]{30}$/', $_REQUEST['key']))) {
		debug('upload', 'missing or malformed input');
		return '404';
	}
	$r=query('SELECT * FROM `builds` WHERE `id`="'.$_REQUEST['build'].'"');
	if ($r->rowCount() == 0) {
		debug('upload', 'build not found');
		return '404';
	}
	$build=new sql_build($r->fetch(PDO::FETCH_ASSOC));
	$opts=$build->get_opts();
	if (!(isset($opts['uploadkey']) && $opts['uploadkey'] == $_REQUEST['key'])) {
		debug('upload', 'invalid upload key');
		return '404';
	}
	contenttype('text/plain');
}
function body_upload(&$S) {
	debug('upload', 'error code: '.$_FILES['file']['error']);
	if ($_FILES['file']['error'] != UPLOAD_ERR_OK)
		die('Upload failed');
	debug('upload', 'Got uploaded file '.$_FILES['file']['name'].' at '.$_FILES['file']['tmp_name']);
	$name=basename($_FILES['file']['name']);
	$ext=substr($name, strpos($name, '.'));
	debug('upload', $_FILES['file']['tmp_name'].' -> '.COMPLETED."/build-$build->id$ext");
	if (!is_writable(COMPLETED))
		die('No write permissions');
	if (!move_uploaded_file($_FILES['file']['tmp_name'], COMPLETED."/build-$build->id$ext"))
		die('Move file failed');
	echo 'Upload successful';
}
?>