blob: 91c11610a38c40b0ceb9e3be3d33eca130059149 (
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
40
41
42
43
|
<?php
function init_downloadimage() {
global $S, $request;
if (!isset($S['user'])) {
return 'login';
}
if (!isset($request['build']) || !preg_match('/^[a-zA-Z0-9]{6}$/', $request['build'])) {
debug('downlaodimage', 'No build or badly formatted build requested');
return '404';
}
$r=$S['pdo']->query('SELECT * FROM `builds` WHERE `owner`='.$S['user']->id.' AND `id`="'.$request['build'].'"');
if ($r->rowCount() == 0) {
debug('downloadimage', 'build not found or not owned by user');
return '404';
}
$build=new sql_build($r->fetch(PDO::FETCH_ASSOC));
$files=glob(COMPLETED.'/build-'.$build->id.'.*');
if (count($files)) {
if (count($files) > 1) {
debug('downloadimage', 'extraneous file(s) found - don\'t know which to give them');
return '404';
}
$S['file']=$files[0];
if (!is_readable($S['file'])) {
debug('downloadimage', 'found file, but no read perms');
return '404';
}
$ext=substr($S['file'], strpos($S['file'], '.'));
} else {
debug('downloadimage', 'image file not found');
return '404';
}
contenttype('application/octet-stream');
header('Content-Length: '.filesize($S['file']));
header('Content-Description: File Transfer');
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="'.(isset($build->name) && strlen($build->name)?str_replace('"', '\"', $build->name):'ingenue-'.$build->id).$ext);
}
function body_downloadimage() {
global $S;
readfile($S['file']);
}
?>
|