source: trunk/admin/include/photos_add_direct_prepare.inc.php @ 11966

Last change on this file since 11966 was 11966, checked in by plg, 13 years ago

feature 2407 added: display upload limitations before file selection (file
maximum size, maximum dimensions, allowed file types). The maximum dimensions
are calculated for GD only (because Imagick and External ImageMagick are not
using PHP memory as far as I could find on the web).

bug 2408 fixed: change term "old style form" into "browser uploader" and
"multiple file form" into "Flash Uploader" (based on WordPress user interface)

File size: 7.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24
25// +-----------------------------------------------------------------------+
26// | Uploaded photos                                                       |
27// +-----------------------------------------------------------------------+
28
29if (isset($page['thumbnails']))
30{
31  $template->assign(
32    array(
33      'thumbnails' => $page['thumbnails'],
34      )
35    );
36
37  // only display the batch link if we have more than 1 photo
38  if (count($page['thumbnails']) > 1)
39  {
40    $template->assign(
41      array(
42        'batch_link' => $page['batch_link'],
43        'batch_label' => sprintf(
44          l10n('Manage this set of %d photos'),
45          count($page['thumbnails'])
46          ),
47        )
48      );
49  }
50}
51
52// +-----------------------------------------------------------------------+
53// | Photo selection                                                       |
54// +-----------------------------------------------------------------------+
55
56$uploadify_path = PHPWG_ROOT_PATH.'admin/include/uploadify';
57
58$upload_max_filesize = min(
59  get_ini_size('upload_max_filesize'),
60  get_ini_size('post_max_size')
61  );
62
63if ($upload_max_filesize == get_ini_size('upload_max_filesize'))
64{
65  $upload_max_filesize_shorthand = get_ini_size('upload_max_filesize', false);
66}
67else
68{
69  $upload_max_filesize_shorthand = get_ini_size('post_max_filesize', false);
70}
71
72$template->assign(
73    array(
74      'F_ADD_ACTION'=> PHOTOS_ADD_BASE_URL,
75      'uploadify_path' => $uploadify_path,
76      'upload_max_filesize' => $upload_max_filesize,
77      'upload_max_filesize_shorthand' => $upload_max_filesize_shorthand,
78    )
79  );
80
81// what is the maximum number of pixels permitted by the memory_limit?
82if (pwg_image::get_library() == 'gd')
83{
84  $fudge_factor = 1.7;
85  $available_memory = get_ini_size('memory_limit') - memory_get_usage();
86  $max_upload_width = round(sqrt($available_memory/(2 * $fudge_factor)));
87  $max_upload_height = round(2 * $max_upload_width / 3);
88  $max_upload_resolution = floor($max_upload_width * $max_upload_height / (1024 * 1024));
89
90  // no need to display a limitation warning if the limitation is huge like 20MP
91  if ($max_upload_resolution < 25)
92  {
93    $template->assign(
94      array(
95        'max_upload_width' => $max_upload_width,
96        'max_upload_height' => $max_upload_height,
97        'max_upload_resolution' => $max_upload_resolution,
98        )
99      );
100  }
101}
102
103$upload_modes = array('html', 'multiple');
104$upload_mode = isset($conf['upload_mode']) ? $conf['upload_mode'] : 'multiple';
105
106if (isset($_GET['upload_mode']) and in_array($_GET['upload_mode'], $upload_modes))
107{
108  $upload_mode = $_GET['upload_mode'];
109  conf_update_param('upload_mode', $upload_mode);
110}
111
112// what is the upload switch mode
113$index_of_upload_mode = array_flip($upload_modes);
114$upload_mode_index = $index_of_upload_mode[$upload_mode];
115$upload_switch = $upload_modes[ ($upload_mode_index + 1) % 2 ];
116
117$template->assign(
118    array(
119      'upload_mode' => $upload_mode,
120      'form_action' => PHOTOS_ADD_BASE_URL.'&amp;upload_mode='.$upload_mode.'&amp;processed=1',
121      'switch_url' => PHOTOS_ADD_BASE_URL.'&amp;upload_mode='.$upload_switch,
122      'upload_id' => md5(rand()),
123      'session_id' => session_id(),
124      'pwg_token' => get_pwg_token(),
125      'another_upload_link' => PHOTOS_ADD_BASE_URL.'&amp;upload_mode='.$upload_mode,
126    )
127  );
128
129$upload_file_types = 'jpeg, png, gif';
130if ('html' == $upload_mode)
131{
132  $upload_file_types.= ', zip';
133}
134$template->assign(
135  array(
136    'upload_file_types' => $upload_file_types,
137    )
138  );
139
140// +-----------------------------------------------------------------------+
141// | Categories                                                            |
142// +-----------------------------------------------------------------------+
143
144// we need to know the category in which the last photo was added
145$selected_category = array();
146$selected_parent = array();
147
148$query = '
149SELECT
150    category_id,
151    id_uppercat
152  FROM '.IMAGES_TABLE.' AS i
153    JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON image_id = i.id
154    JOIN '.CATEGORIES_TABLE.' AS c ON category_id = c.id
155  ORDER BY i.id DESC
156  LIMIT 1
157;';
158$result = pwg_query($query);
159if (pwg_db_num_rows($result) > 0)
160{
161  $row = pwg_db_fetch_assoc($result);
162 
163  $selected_category = array($row['category_id']);
164
165  if (!empty($row['id_uppercat']))
166  {
167    $selected_parent = array($row['id_uppercat']);
168  }
169}
170
171// existing album
172$query = '
173SELECT id,name,uppercats,global_rank
174  FROM '.CATEGORIES_TABLE.'
175;';
176
177display_select_cat_wrapper(
178  $query,
179  $selected_category,
180  'category_options'
181  );
182
183// new category
184display_select_cat_wrapper(
185  $query,
186  $selected_parent,
187  'category_parent_options'
188  );
189
190
191// image level options
192$selected_level = isset($_POST['level']) ? $_POST['level'] : 0;
193$template->assign(
194    array(
195      'level_options'=> get_privacy_level_options(),
196      'level_options_selected' => array($selected_level)
197    )
198  );
199
200// +-----------------------------------------------------------------------+
201// | Setup errors/warnings                                                 |
202// +-----------------------------------------------------------------------+
203
204// Errors
205$setup_errors = array();
206
207$error_message = ready_for_upload_message();
208if (!empty($error_message))
209{
210  array_push($setup_errors, $error_message);
211}
212
213if (!function_exists('gd_info'))
214{
215  array_push($setup_errors, l10n('GD library is missing'));
216}
217
218$template->assign(
219  array(
220    'setup_errors'=> $setup_errors,
221    )
222  );
223
224// Warnings
225if (isset($_GET['hide_warnings']))
226{
227  $_SESSION['upload_hide_warnings'] = true;
228}
229
230if (!isset($_SESSION['upload_hide_warnings']))
231{
232  $setup_warnings = array();
233 
234  if ($conf['use_exif'] and !function_exists('read_exif_data'))
235  {
236    array_push(
237      $setup_warnings,
238      l10n('Exif extension not available, admin should disable exif use')
239      );
240  }
241
242  if (get_ini_size('upload_max_filesize') > get_ini_size('post_max_size'))
243  {
244    array_push(
245      $setup_warnings,
246      sprintf(
247        l10n('In your php.ini file, the upload_max_filesize (%sB) is bigger than post_max_size (%sB), you should change this setting'),
248        get_ini_size('upload_max_filesize', false),
249        get_ini_size('post_max_size', false)
250        )
251      );
252  }
253
254  $template->assign(
255    array(
256      'setup_warnings' => $setup_warnings,
257      'hide_warnings_link' => PHOTOS_ADD_BASE_URL.'&amp;upload_mode='.$upload_mode.'&amp;hide_warnings=1'
258      )
259    );
260}
261
262?>
Note: See TracBrowser for help on using the repository browser.