thomascube
2008-09-18 7dfb1fba5001299300736e6b5d95d9400575e3e7
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
7ffc08 23 if (!$_SESSION['compose']) {
T 24   die("Invalid session var!");
25 }
4e17e6 26
T 27
70d4b9 28 // use common temp dir for file uploads
T 29 $temp_dir = unslashify($CONFIG['temp_dir']);
597170 30
4e17e6 31
6d5dba 32 if (!is_array($_SESSION['compose']['attachments'])) {
4e17e6 33   $_SESSION['compose']['attachments'] = array();
6d5dba 34 }
4e17e6 35
7ffc08 36 // clear all stored output properties (like scripts and env vars)
T 37 $OUTPUT->reset();
4e17e6 38
6d5dba 39 if (is_array($_FILES['_attachments']['tmp_name'])) {
T 40   foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath) {
599843 41     $tmpfname = tempnam($temp_dir, 'rcmAttmnt');
6d5dba 42     if (move_uploaded_file($filepath, $tmpfname)) {
599843 43       $id = count($_SESSION['compose']['attachments']);
6d5dba 44       $_SESSION['compose']['attachments'][] = array(
T 45         'name' => $_FILES['_attachments']['name'][$i],
46         'mimetype' => rc_mime_content_type($tmpfname, $_FILES['_attachments']['type'][$i]),
47         'path' => $tmpfname,
48       );
4e17e6 49
6d5dba 50       if (is_file($icon = $CONFIG['skin_path'] . '/images/icons/remove-attachment.png')) {
T 51         $button = html::img(array(
52           'src' => $icon,
53           'border' => 0,
54           'alt' => rcube_label('delete'),
55           'style' => "padding-right:2px;vertical-align:middle",
56         ));
599843 57       }
6d5dba 58       else {
T 59         $button = Q(rcube_label('delete'));
60       }
61
62       $content = html::a(array(
63         'href' => "#delete",
64         'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%d', this)", JS_OBJECT_NAME, $id),
65         'title' => rcube_label('delete'),
66       ), $button);
67       
68       $content .= Q($_FILES['_attachments']['name'][$i]);
69       
70       $OUTPUT->command('add2attachment_list', "rcmfile$id", $content);
71     }
72     else {  // upload failed
599843 73       $err = $_FILES['_attachments']['error'][$i];
6d5dba 74       if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) {
599843 75         $msg = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize'))))));
6d5dba 76       }
T 77       else {
599843 78         $msg = rcube_label('fileuploaderror');
6d5dba 79       }
86df15 80     
599843 81       $OUTPUT->command('display_message', $msg, 'error');
86df15 82     }
4e17e6 83   }
6d5dba 84 }
T 85 else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
e34545 86   $OUTPUT->command('display_message', rcube_label('fileuploaderror'), 'error');
6d5dba 87 }
4e17e6 88
T 89 // send html page with JS calls as response
f11541 90 $OUTPUT->command('show_attachment_form', false);
T 91 $OUTPUT->command('auto_save_start', false);
92 $OUTPUT->send('iframe');
4e17e6 93
599843 94 ?>