thomascube
2006-01-25 c9d09bbe43f268c11cadc9846652ff33521edf6c
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                     |
8  | Copyright (C) 2005, 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
597170 29 // create temp dir for file uploads
T 30 $temp_dir = rcmail_create_compose_tempdir();
31
4e17e6 32
T 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');
15a9d1 42   if (move_uploaded_file($filepath, $tmpfname))
4e17e6 43     {
T 44     $_SESSION['compose']['attachments'][] = array('name' => $_FILES['_attachments']['name'][$i],
45                                                   'mimetype' => $_FILES['_attachments']['type'][$i],
46                                                   'path' => $tmpfname);
47
48     $response .= sprintf("parent.%s.add2attachment_list('%s');\n", $JS_OBJECT_NAME, $_FILES['_attachments']['name'][$i]);
49     }
50   }
51
52
53 // send html page with JS calls as response
54 print <<<EOF
55 <html>
56 <script type="text/javascript">
57 if (parent.$JS_OBJECT_NAME)
58 {
59 $response
60 parent.$JS_OBJECT_NAME.show_attachment_form(false);
61 }
62 </script>
63 </html>
64 EOF;
65 exit;
66
67 ?>