4 +-----------------------------------------------------------------------+
5 | program/steps/mail/upload.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Handle file-upload and make them available as attachments |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: upload.inc 1434 2008-05-27 14:58:04Z thomasb $
23 if (!$_SESSION['compose']) {
24 die("Invalid session var!");
28 // use common temp dir for file uploads
29 $temp_dir = unslashify($CONFIG['temp_dir']);
32 if (!is_array($_SESSION['compose']['attachments']))
33 $_SESSION['compose']['attachments'] = array();
36 // clear all stored output properties (like scripts and env vars)
39 if (is_array($_FILES['_attachments']['tmp_name']))
41 foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath)
43 $tmpfname = tempnam($temp_dir, 'rcmAttmnt');
44 if (move_uploaded_file($filepath, $tmpfname))
46 $id = count($_SESSION['compose']['attachments']);
47 $_SESSION['compose']['attachments'][] = array('name' => $_FILES['_attachments']['name'][$i],
48 'mimetype' => $_FILES['_attachments']['type'][$i],
51 if (is_file($CONFIG['skin_path'] . '/images/icons/remove-attachment.png'))
53 '<img src="%s/images/icons/remove-attachment.png" alt="%s" border="0" style="padding-right:2px;vertical-align:middle" />',
55 Q(rcube_label('delete')));
57 $button = Q(rcube_label('delete'));
60 '<a href="#delete" onclick="return %s.command(\'remove-attachment\', \'rcmfile%d\', this)" title="%s">%s</a>%s',
63 Q(rcube_label('delete')),
65 Q($_FILES['_attachments']['name'][$i]));
67 $OUTPUT->command('add2attachment_list', "rcmfile$id", $content);
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'))))));
75 $msg = rcube_label('fileuploaderror');
77 $OUTPUT->command('display_message', $msg, 'error');
81 else if ($_SERVER['REQUEST_METHOD'] == 'POST')
83 $OUTPUT->command('display_message', rcube_label('fileuploaderror'), 'error');
86 // send html page with JS calls as response
87 $OUTPUT->command('show_attachment_form', false);
88 $OUTPUT->command('auto_save_start', false);
89 $OUTPUT->send('iframe');