summaryrefslogtreecommitdiff
blob: 5f71eb3da59944ac1537395af77f1b4be7efb06d (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
35
36
37
38
39
<?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';
	}
	debug('upload', 'error code: '.$_FILES['file']['error']);
	if ($_FILES['file']['error'] != UPLOAD_ERR_OK) {
		return '404';
	}
	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)) {
		debug('upload', 'Web server needs write permissions for '.COMPLETED);
		return '404';
	}
	if (!move_uploaded_file($_FILES['file']['tmp_name'], COMPLETED."/build-$build->id$ext")) {
		debug('Move file failed');
		return '404';
	}
	return array('title' => 'Upload Successful');
}
function body_upload() {
	echo print_success('Upload successful');
}
?>