comparison program/steps/addressbook/upload_photo.inc @ 0:4681f974d28b

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:52:31 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4681f974d28b
1 <?php
2
3 /**
4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/upload_photo.inc |
6 | |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2011, The Roundcube Dev Team |
9 | |
10 | Licensed under the GNU General Public License version 3 or |
11 | any later version with exceptions for skins & plugins. |
12 | See the README file for a full license statement. |
13 | |
14 | PURPOSE: |
15 | Handles contact photo uploads |
16 | |
17 +-----------------------------------------------------------------------+
18 | Author: Thomas Bruederli <roundcube@gmail.com> |
19 +-----------------------------------------------------------------------+
20 */
21
22 // Supported image format types
23 // ImageMagick works with other non-image types (e.g.pdf) we don't want here
24 $IMAGE_TYPES = explode(',', 'jpeg,jpg,jp2,tiff,tif,bmp,eps,gif,png,png8,png24,png32,svg,ico');
25
26 // clear all stored output properties (like scripts and env vars)
27 $OUTPUT->reset();
28
29 if ($filepath = $_FILES['_photo']['tmp_name']) {
30 // check file type and resize image
31 $image = new rcube_image($_FILES['_photo']['tmp_name']);
32 $imageprop = $image->props();
33
34 if (in_array(strtolower($imageprop['type']), $IMAGE_TYPES)
35 && $imageprop['width'] && $imageprop['height']
36 ) {
37 $maxsize = intval($RCMAIL->config->get('contact_photo_size', 160));
38 $tmpfname = tempnam($RCMAIL->config->get('temp_dir'), 'rcmImgConvert');
39 $save_hook = 'attachment_upload';
40
41 // scale image to a maximum size
42 if (($imageprop['width'] > $maxsize || $imageprop['height'] > $maxsize) && $image->resize($maxsize, $tmpfname)) {
43 $filepath = $tmpfname;
44 $save_hook = 'attachment_save';
45 }
46
47 // save uploaded file in storage backend
48 $attachment = $RCMAIL->plugins->exec_hook($save_hook, array(
49 'path' => $filepath,
50 'size' => $_FILES['_photo']['size'],
51 'name' => $_FILES['_photo']['name'],
52 'mimetype' => 'image/' . $imageprop['type'],
53 'group' => 'contact',
54 ));
55 }
56 else {
57 $attachment['error'] = $RCMAIL->gettext('invalidimageformat');
58 }
59
60 if ($attachment['status'] && !$attachment['abort']) {
61 $file_id = $attachment['id'];
62 $_SESSION['contacts']['files'][$file_id] = $attachment;
63 $OUTPUT->command('replace_contact_photo', $file_id);
64 }
65 else { // upload failed
66 $err = $_FILES['_photo']['error'];
67 $size = $RCMAIL->show_bytes(rcube_utils::max_upload_size());
68
69 if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE)
70 $msg = $RCMAIL->gettext(array('name' => 'filesizeerror', 'vars' => array('size' => $size)));
71 else if ($attachment['error'])
72 $msg = $attachment['error'];
73 else
74 $msg = $RCMAIL->gettext('fileuploaderror');
75
76 $OUTPUT->command('display_message', $msg, 'error');
77 }
78 }
79 else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
80 // if filesize exceeds post_max_size then $_FILES array is empty,
81 // show filesizeerror instead of fileuploaderror
82 if ($maxsize = ini_get('post_max_size'))
83 $msg = $RCMAIL->gettext(array('name' => 'filesizeerror', 'vars' => array('size' => $RCMAIL->show_bytes(parse_bytes($maxsize)))));
84 else
85 $msg = $RCMAIL->gettext('fileuploaderror');
86
87 $OUTPUT->command('display_message', $msg, 'error');
88 }
89
90 $OUTPUT->command('photo_upload_end');
91 $OUTPUT->send('iframe');