commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/mail/upload.inc | |
|
6 |
| | |
|
7 |
| This file is part of the RoundCube Webmail client | |
5349b7
|
8 |
| Copyright (C) 2005-2007, RoundCube Dev. - Switzerland | |
30233b
|
9 |
| Licensed under the GNU GPL | |
4e17e6
|
10 |
| | |
T |
11 |
| PURPOSE: | |
|
12 |
| Handle file-upload and make them available as attachments | |
|
13 |
| | |
|
14 |
+-----------------------------------------------------------------------+ |
|
15 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
16 |
+-----------------------------------------------------------------------+ |
|
17 |
|
|
18 |
$Id$ |
|
19 |
|
|
20 |
*/ |
|
21 |
|
|
22 |
|
|
23 |
if (!$_SESSION['compose']) |
|
24 |
{ |
|
25 |
exit; |
|
26 |
} |
|
27 |
|
|
28 |
|
70d4b9
|
29 |
// use common temp dir for file uploads |
T |
30 |
$temp_dir = unslashify($CONFIG['temp_dir']); |
597170
|
31 |
|
4e17e6
|
32 |
|
T |
33 |
if (!is_array($_SESSION['compose']['attachments'])) |
|
34 |
$_SESSION['compose']['attachments'] = array(); |
|
35 |
|
|
36 |
|
|
37 |
$response = ''; |
|
38 |
|
599843
|
39 |
if (is_array($_FILES['_attachments']['tmp_name'])) |
4e17e6
|
40 |
{ |
599843
|
41 |
foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath) |
4e17e6
|
42 |
{ |
599843
|
43 |
$tmpfname = tempnam($temp_dir, 'rcmAttmnt'); |
T |
44 |
if (move_uploaded_file($filepath, $tmpfname)) |
|
45 |
{ |
|
46 |
$id = count($_SESSION['compose']['attachments']); |
|
47 |
$_SESSION['compose']['attachments'][] = array('name' => $_FILES['_attachments']['name'][$i], |
4e17e6
|
48 |
'mimetype' => $_FILES['_attachments']['type'][$i], |
T |
49 |
'path' => $tmpfname); |
|
50 |
|
599843
|
51 |
if (is_file($CONFIG['skin_path'] . '/images/icons/remove-attachment.png')) |
T |
52 |
$button = sprintf( |
|
53 |
'<img src="%s/images/icons/remove-attachment.png" alt="%s" border="0" style="padding-right:2px;vertical-align:middle" />', |
|
54 |
$CONFIG['skin_path'], |
|
55 |
Q(rcube_label('delete'))); |
|
56 |
else |
|
57 |
$button = Q(rcube_label('delete')); |
aade7b
|
58 |
|
599843
|
59 |
$content = sprintf( |
T |
60 |
'<a href="#delete" onclick="return %s.command(\'remove-attachment\', \'rcmfile%d\', this)" title="%s">%s</a>%s', |
|
61 |
JS_OBJECT_NAME, |
|
62 |
$id, |
|
63 |
Q(rcube_label('delete')), |
|
64 |
$button, |
|
65 |
Q($_FILES['_attachments']['name'][$i])); |
aade7b
|
66 |
|
599843
|
67 |
$OUTPUT->command('add2attachment_list', "rcmfile$id", $content); |
T |
68 |
} |
|
69 |
else // upload failed |
|
70 |
{ |
|
71 |
$err = $_FILES['_attachments']['error'][$i]; |
|
72 |
if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) |
|
73 |
$msg = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize')))))); |
|
74 |
else |
|
75 |
$msg = rcube_label('fileuploaderror'); |
86df15
|
76 |
|
599843
|
77 |
$OUTPUT->command('display_message', $msg, 'error'); |
T |
78 |
} |
86df15
|
79 |
} |
4e17e6
|
80 |
} |
e34545
|
81 |
else if ($_SERVER['REQUEST_METHOD'] == 'POST') |
A |
82 |
{ |
|
83 |
$OUTPUT->command('display_message', rcube_label('fileuploaderror'), 'error'); |
|
84 |
} |
4e17e6
|
85 |
|
T |
86 |
// send html page with JS calls as response |
f11541
|
87 |
$OUTPUT->command('show_attachment_form', false); |
T |
88 |
$OUTPUT->command('auto_save_start', false); |
|
89 |
$OUTPUT->send('iframe'); |
4e17e6
|
90 |
|
599843
|
91 |
?> |