]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/upload.inc
Imported Upstream version 0.1~rc1~dfsg
[roundcube.git] / program / steps / mail / upload.inc
1 <?php
2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/mail/upload.inc                                         |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
8  | Copyright (C) 2005, RoundCube Dev. - Switzerland                      |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
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: upload.inc 543 2007-04-28 18:07:12Z thomasb $
19
20 */
21
22
23 if (!$_SESSION['compose'])
24   {
25   exit;
26   }
27
28
29 // use common temp dir for file uploads
30 $temp_dir = unslashify($CONFIG['temp_dir']);
31
32
33 if (!is_array($_SESSION['compose']['attachments']))
34   $_SESSION['compose']['attachments'] = array();
35
36
37 $response = '';
38
39 foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath)
40   {
41   $tmpfname = tempnam($temp_dir, 'rcmAttmnt');
42   if (move_uploaded_file($filepath, $tmpfname))
43     {
44     $id = count($_SESSION['compose']['attachments']);
45     $_SESSION['compose']['attachments'][] = array('name' => $_FILES['_attachments']['name'][$i],
46                                                   'mimetype' => $_FILES['_attachments']['type'][$i],
47                                                   'path' => $tmpfname);
48
49     if (is_file($CONFIG['skin_path'] . '/images/icons/remove-attachment.png'))
50       $button = sprintf(
51         '<img src="%s/images/icons/remove-attachment.png" alt="%s" border="0" style="padding-right:2px;vertical-align:middle" />',
52         $CONFIG['skin_path'],
53         Q(rcube_label('delete')));
54     else
55       $button = Q(rcube_label('delete'));
56
57     $content = sprintf(
58       '<a href="#delete" onclick="return %s.command(\'remove-attachment\', \'rcmfile%d\', this)" title="%s">%s</a>%s',
59       JS_OBJECT_NAME,
60       $id,
61       Q(rcube_label('delete')),
62       $button,
63       Q($_FILES['_attachments']['name'][$i]));
64
65     $OUTPUT->command('add2attachment_list', "rcmfile$id", $content);
66     }
67   else // upload failed
68     {
69     $err = $_FILES['_attachments']['error'][$i];
70     if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE)
71       $msg = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize'))))));
72     else
73       $msg = rcube_label('fileuploaderror');
74     
75     $OUTPUT->command('display_message', $msg, 'error');
76     }
77   }
78
79
80 // send html page with JS calls as response
81 $OUTPUT->command('show_attachment_form', false);
82 $OUTPUT->command('auto_save_start', false);
83 $OUTPUT->send('iframe');
84
85 ?>