4 +-----------------------------------------------------------------------+
5 | program/steps/mail/attachments.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Upload, remove, display attachments in compose form |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: compose.inc 2081 2008-11-23 12:38:44Z thomasb $
23 if (!$_SESSION['compose']) {
24 die("Invalid session var!");
28 // remove an attachment
29 if ($RCMAIL->action=='remove-attachment')
31 if (preg_match('/^rcmfile([0-9]+)$/', $_POST['_file'], $regs))
34 if (is_array($_SESSION['compose']['attachments'][$id]))
36 @unlink($_SESSION['compose']['attachments'][$id]['path']);
37 unset($_SESSION['compose']['attachments'][$id]);
38 $OUTPUT->command('remove_from_attachment_list', "rcmfile$id");
45 if ($RCMAIL->action=='display-attachment')
47 if (preg_match('/^rcmfile([0-9]+)$/', $_GET['_file'], $regs))
50 if (is_array($_SESSION['compose']['attachments'][$id]))
52 $apath = $_SESSION['compose']['attachments'][$id]['path'];
53 header('Content-Type: ' . $_SESSION['compose']['attachments'][$id]['mimetype']);
54 header('Content-Length: ' . filesize($apath));
61 // attachment upload action
63 // use common temp dir for file uploads
64 $temp_dir = unslashify($CONFIG['temp_dir']);
66 if (!is_array($_SESSION['compose']['attachments'])) {
67 $_SESSION['compose']['attachments'] = array();
70 // clear all stored output properties (like scripts and env vars)
73 if (is_array($_FILES['_attachments']['tmp_name'])) {
74 foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath) {
75 $tmpfname = tempnam($temp_dir, 'rcmAttmnt');
76 if (move_uploaded_file($filepath, $tmpfname)) {
77 $id = count($_SESSION['compose']['attachments']);
78 $_SESSION['compose']['attachments'][] = array(
79 'name' => $_FILES['_attachments']['name'][$i],
80 'mimetype' => rc_mime_content_type($tmpfname, $_FILES['_attachments']['name'][$i], $_FILES['_attachments']['type'][$i]),
84 if (is_file($icon = $CONFIG['skin_path'] . '/images/icons/remove-attachment.png')) {
85 $button = html::img(array(
87 'alt' => rcube_label('delete'),
88 'style' => "padding-right:2px;vertical-align:middle",
92 $button = Q(rcube_label('delete'));
95 $content = html::a(array(
97 'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%d', this)", JS_OBJECT_NAME, $id),
98 'title' => rcube_label('delete'),
101 $content .= Q($_FILES['_attachments']['name'][$i]);
103 $OUTPUT->command('add2attachment_list', "rcmfile$id", $content);
105 else { // upload failed
106 $err = $_FILES['_attachments']['error'][$i];
107 if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) {
108 $msg = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize'))))));
111 $msg = rcube_label('fileuploaderror');
114 $OUTPUT->command('display_message', $msg, 'error');
118 else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
119 $OUTPUT->command('display_message', rcube_label('fileuploaderror'), 'error');
122 // send html page with JS calls as response
123 $OUTPUT->command('show_attachment_form', false);
124 $OUTPUT->command('auto_save_start', false);
125 $OUTPUT->send('iframe');