[5089] | 1 | <?php |
---|
[8249] | 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[8249] | 4 | // +-----------------------------------------------------------------------+ |
---|
[19703] | 5 | // | Copyright(C) 2008-2013 Piwigo Team http://piwigo.org | |
---|
[8249] | 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 | // +-----------------------------------------------------------------------+ |
---|
[5089] | 23 | |
---|
| 24 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
[10641] | 25 | include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php'); |
---|
[5089] | 26 | |
---|
[5957] | 27 | // add default event handler for image and thumbnail resize |
---|
[8219] | 28 | add_event_handler('upload_image_resize', 'pwg_image_resize', EVENT_HANDLER_PRIORITY_NEUTRAL, 7); |
---|
[10552] | 29 | add_event_handler('upload_thumbnail_resize', 'pwg_image_resize', EVENT_HANDLER_PRIORITY_NEUTRAL, 9); |
---|
[5957] | 30 | |
---|
[8249] | 31 | function get_upload_form_config() |
---|
| 32 | { |
---|
| 33 | // default configuration for upload |
---|
| 34 | $upload_form_config = array( |
---|
[12879] | 35 | 'original_resize' => array( |
---|
[10552] | 36 | 'default' => false, |
---|
| 37 | 'can_be_null' => false, |
---|
| 38 | ), |
---|
[12917] | 39 | |
---|
[12879] | 40 | 'original_resize_maxwidth' => array( |
---|
[8249] | 41 | 'default' => 2000, |
---|
| 42 | 'min' => 500, |
---|
| 43 | 'max' => 20000, |
---|
| 44 | 'pattern' => '/^\d+$/', |
---|
| 45 | 'can_be_null' => false, |
---|
[12879] | 46 | 'error_message' => l10n('The original maximum width must be a number between %d and %d'), |
---|
[8249] | 47 | ), |
---|
[12917] | 48 | |
---|
[12879] | 49 | 'original_resize_maxheight' => array( |
---|
[8249] | 50 | 'default' => 2000, |
---|
[12879] | 51 | 'min' => 300, |
---|
[8249] | 52 | 'max' => 20000, |
---|
| 53 | 'pattern' => '/^\d+$/', |
---|
| 54 | 'can_be_null' => false, |
---|
[12879] | 55 | 'error_message' => l10n('The original maximum height must be a number between %d and %d'), |
---|
[8249] | 56 | ), |
---|
[12917] | 57 | |
---|
[12879] | 58 | 'original_resize_quality' => array( |
---|
[8249] | 59 | 'default' => 95, |
---|
| 60 | 'min' => 50, |
---|
[12879] | 61 | 'max' => 98, |
---|
[8249] | 62 | 'pattern' => '/^\d+$/', |
---|
| 63 | 'can_be_null' => false, |
---|
[12879] | 64 | 'error_message' => l10n('The original image quality must be a number between %d and %d'), |
---|
[8249] | 65 | ), |
---|
| 66 | ); |
---|
| 67 | |
---|
| 68 | return $upload_form_config; |
---|
| 69 | } |
---|
| 70 | |
---|
[14221] | 71 | function save_upload_form_config($data, &$errors=array(), &$form_errors=array()) |
---|
[10589] | 72 | { |
---|
| 73 | if (!is_array($data) or empty($data)) |
---|
| 74 | { |
---|
| 75 | return false; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | $upload_form_config = get_upload_form_config(); |
---|
| 79 | $updates = array(); |
---|
| 80 | |
---|
| 81 | foreach ($data as $field => $value) |
---|
| 82 | { |
---|
| 83 | if (!isset($upload_form_config[$field])) |
---|
| 84 | { |
---|
| 85 | continue; |
---|
| 86 | } |
---|
| 87 | if (is_bool($upload_form_config[$field]['default'])) |
---|
| 88 | { |
---|
| 89 | if (isset($value)) |
---|
| 90 | { |
---|
| 91 | $value = true; |
---|
| 92 | } |
---|
| 93 | else |
---|
| 94 | { |
---|
| 95 | $value = false; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | $updates[] = array( |
---|
[12879] | 99 | 'param' => $field, |
---|
[10589] | 100 | 'value' => boolean_to_string($value) |
---|
| 101 | ); |
---|
| 102 | } |
---|
| 103 | elseif ($upload_form_config[$field]['can_be_null'] and empty($value)) |
---|
| 104 | { |
---|
| 105 | $updates[] = array( |
---|
[12879] | 106 | 'param' => $field, |
---|
[10589] | 107 | 'value' => 'false' |
---|
| 108 | ); |
---|
| 109 | } |
---|
| 110 | else |
---|
| 111 | { |
---|
| 112 | $min = $upload_form_config[$field]['min']; |
---|
| 113 | $max = $upload_form_config[$field]['max']; |
---|
| 114 | $pattern = $upload_form_config[$field]['pattern']; |
---|
[12917] | 115 | |
---|
[10589] | 116 | if (preg_match($pattern, $value) and $value >= $min and $value <= $max) |
---|
| 117 | { |
---|
| 118 | $updates[] = array( |
---|
[12879] | 119 | 'param' => $field, |
---|
[10589] | 120 | 'value' => $value |
---|
| 121 | ); |
---|
| 122 | } |
---|
| 123 | else |
---|
| 124 | { |
---|
[25018] | 125 | $errors[] = sprintf( |
---|
| 126 | $upload_form_config[$field]['error_message'], |
---|
| 127 | $min, $max |
---|
[10589] | 128 | ); |
---|
[14221] | 129 | |
---|
| 130 | $form_errors[$field] = '['.$min.' .. '.$max.']'; |
---|
[10589] | 131 | } |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | if (count($errors) == 0) |
---|
| 136 | { |
---|
| 137 | mass_updates( |
---|
| 138 | CONFIG_TABLE, |
---|
| 139 | array( |
---|
| 140 | 'primary' => array('param'), |
---|
| 141 | 'update' => array('value') |
---|
| 142 | ), |
---|
| 143 | $updates |
---|
| 144 | ); |
---|
| 145 | return true; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | return false; |
---|
| 149 | } |
---|
| 150 | |
---|
[12906] | 151 | function add_uploaded_file($source_filepath, $original_filename=null, $categories=null, $level=null, $image_id=null, $original_md5sum=null) |
---|
[5089] | 152 | { |
---|
[8249] | 153 | // 1) move uploaded file to upload/2010/01/22/20100122003814-449ada00.jpg |
---|
| 154 | // |
---|
[12879] | 155 | // 2) keep/resize original |
---|
[8249] | 156 | // |
---|
[12879] | 157 | // 3) register in database |
---|
[12917] | 158 | |
---|
[8249] | 159 | // TODO |
---|
| 160 | // * check md5sum (already exists?) |
---|
[12917] | 161 | |
---|
[8464] | 162 | global $conf, $user; |
---|
[5089] | 163 | |
---|
[12906] | 164 | if (isset($original_md5sum)) |
---|
| 165 | { |
---|
| 166 | $md5sum = $original_md5sum; |
---|
| 167 | } |
---|
| 168 | else |
---|
| 169 | { |
---|
| 170 | $md5sum = md5_file($source_filepath); |
---|
| 171 | } |
---|
[12917] | 172 | |
---|
[9191] | 173 | $file_path = null; |
---|
[25929] | 174 | $is_tiff = false; |
---|
[12917] | 175 | |
---|
[9191] | 176 | if (isset($image_id)) |
---|
| 177 | { |
---|
[12879] | 178 | // this photo already exists, we update it |
---|
[9191] | 179 | $query = ' |
---|
| 180 | SELECT |
---|
| 181 | path |
---|
| 182 | FROM '.IMAGES_TABLE.' |
---|
| 183 | WHERE id = '.$image_id.' |
---|
| 184 | ;'; |
---|
| 185 | $result = pwg_query($query); |
---|
| 186 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 187 | { |
---|
| 188 | $file_path = $row['path']; |
---|
| 189 | } |
---|
[12917] | 190 | |
---|
[9191] | 191 | if (!isset($file_path)) |
---|
| 192 | { |
---|
| 193 | die('['.__FUNCTION__.'] this photo does not exist in the database'); |
---|
| 194 | } |
---|
[5089] | 195 | |
---|
[9191] | 196 | // delete all physical files related to the photo (thumbnail, web site, HD) |
---|
| 197 | delete_element_files(array($image_id)); |
---|
[6617] | 198 | } |
---|
| 199 | else |
---|
| 200 | { |
---|
[9191] | 201 | // this photo is new |
---|
[12917] | 202 | |
---|
[9191] | 203 | // current date |
---|
| 204 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
| 205 | list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4); |
---|
[12917] | 206 | |
---|
[9191] | 207 | // upload directory hierarchy |
---|
| 208 | $upload_dir = sprintf( |
---|
| 209 | PHPWG_ROOT_PATH.$conf['upload_dir'].'/%s/%s/%s', |
---|
| 210 | $year, |
---|
| 211 | $month, |
---|
| 212 | $day |
---|
| 213 | ); |
---|
| 214 | |
---|
| 215 | // compute file path |
---|
| 216 | $date_string = preg_replace('/[^\d]/', '', $dbnow); |
---|
| 217 | $random_string = substr($md5sum, 0, 8); |
---|
| 218 | $filename_wo_ext = $date_string.'-'.$random_string; |
---|
| 219 | $file_path = $upload_dir.'/'.$filename_wo_ext.'.'; |
---|
| 220 | |
---|
| 221 | list($width, $height, $type) = getimagesize($source_filepath); |
---|
| 222 | if (IMAGETYPE_PNG == $type) |
---|
| 223 | { |
---|
| 224 | $file_path.= 'png'; |
---|
| 225 | } |
---|
[9952] | 226 | elseif (IMAGETYPE_GIF == $type) |
---|
| 227 | { |
---|
| 228 | $file_path.= 'gif'; |
---|
| 229 | } |
---|
[25929] | 230 | elseif (IMAGETYPE_TIFF_MM == $type or IMAGETYPE_TIFF_II == $type) |
---|
| 231 | { |
---|
| 232 | $is_tiff = true; |
---|
| 233 | $file_path.= 'tif'; |
---|
| 234 | } |
---|
[9191] | 235 | else |
---|
| 236 | { |
---|
| 237 | $file_path.= 'jpg'; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | prepare_directory($upload_dir); |
---|
[6617] | 241 | } |
---|
| 242 | |
---|
[5089] | 243 | if (is_uploaded_file($source_filepath)) |
---|
| 244 | { |
---|
| 245 | move_uploaded_file($source_filepath, $file_path); |
---|
| 246 | } |
---|
| 247 | else |
---|
| 248 | { |
---|
[12906] | 249 | rename($source_filepath, $file_path); |
---|
[5089] | 250 | } |
---|
[17675] | 251 | @chmod($file_path, 0644); |
---|
[5089] | 252 | |
---|
[25929] | 253 | if ($is_tiff and pwg_image::get_library() == 'ext_imagick') |
---|
| 254 | { |
---|
| 255 | // move the uploaded file to pwg_representative sub-directory |
---|
| 256 | $representative_file_path = dirname($file_path).'/pwg_representative/'; |
---|
| 257 | $representative_file_path.= get_filename_wo_extension(basename($file_path)).'.'; |
---|
| 258 | |
---|
| 259 | $representative_ext = $conf['tiff_representative_ext']; |
---|
| 260 | $representative_file_path.= $representative_ext; |
---|
| 261 | |
---|
| 262 | prepare_directory(dirname($representative_file_path)); |
---|
| 263 | |
---|
| 264 | $exec = $conf['ext_imagick_dir'].'convert'; |
---|
| 265 | |
---|
| 266 | if ('jpg' == $conf['tiff_representative_ext']) |
---|
| 267 | { |
---|
| 268 | $exec .= ' -quality 98'; |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | $exec .= ' "'.realpath($file_path).'"'; |
---|
| 272 | |
---|
| 273 | $dest = pathinfo($representative_file_path); |
---|
| 274 | $exec .= ' "'.realpath($dest['dirname']).'/'.$dest['basename'].'"'; |
---|
| 275 | |
---|
| 276 | $exec .= ' 2>&1'; |
---|
| 277 | @exec($exec, $returnarray); |
---|
| 278 | |
---|
| 279 | // sometimes ImageMagick creates file-0.jpg (full size) + file-1.jpg |
---|
| 280 | // (thumbnail). I don't know how to avoid it. |
---|
| 281 | $representative_file_abspath = realpath($dest['dirname']).'/'.$dest['basename']; |
---|
| 282 | if (!file_exists($representative_file_abspath)) |
---|
| 283 | { |
---|
| 284 | $first_file_abspath = preg_replace( |
---|
| 285 | '/\.'.$representative_ext.'$/', |
---|
| 286 | '-0.'.$representative_ext, |
---|
| 287 | $representative_file_abspath |
---|
| 288 | ); |
---|
| 289 | |
---|
| 290 | if (file_exists($first_file_abspath)) |
---|
| 291 | { |
---|
| 292 | rename($first_file_abspath, $representative_file_abspath); |
---|
| 293 | } |
---|
| 294 | } |
---|
| 295 | } |
---|
| 296 | |
---|
[12879] | 297 | if (pwg_image::get_library() != 'gd') |
---|
[5089] | 298 | { |
---|
[12879] | 299 | if ($conf['original_resize']) |
---|
[8227] | 300 | { |
---|
[12879] | 301 | $need_resize = need_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight']); |
---|
[12917] | 302 | |
---|
[12879] | 303 | if ($need_resize) |
---|
[8227] | 304 | { |
---|
[12879] | 305 | $img = new pwg_image($file_path); |
---|
[12917] | 306 | |
---|
[12879] | 307 | $img->pwg_resize( |
---|
| 308 | $file_path, |
---|
| 309 | $conf['original_resize_maxwidth'], |
---|
| 310 | $conf['original_resize_maxheight'], |
---|
| 311 | $conf['original_resize_quality'], |
---|
| 312 | $conf['upload_form_automatic_rotation'], |
---|
| 313 | false |
---|
| 314 | ); |
---|
[12917] | 315 | |
---|
[12879] | 316 | $img->destroy(); |
---|
[8227] | 317 | } |
---|
| 318 | } |
---|
[5089] | 319 | } |
---|
| 320 | |
---|
[13843] | 321 | // we need to save the rotation angle in the database to compute |
---|
| 322 | // width/height of "multisizes" |
---|
| 323 | $rotation_angle = pwg_image::get_rotation_angle($file_path); |
---|
| 324 | $rotation = pwg_image::get_rotation_code_from_angle($rotation_angle); |
---|
| 325 | |
---|
[5089] | 326 | $file_infos = pwg_image_infos($file_path); |
---|
[12917] | 327 | |
---|
[9191] | 328 | if (isset($image_id)) |
---|
| 329 | { |
---|
| 330 | $update = array( |
---|
| 331 | 'file' => pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)), |
---|
| 332 | 'filesize' => $file_infos['filesize'], |
---|
| 333 | 'width' => $file_infos['width'], |
---|
| 334 | 'height' => $file_infos['height'], |
---|
| 335 | 'md5sum' => $md5sum, |
---|
| 336 | 'added_by' => $user['id'], |
---|
[13843] | 337 | 'rotation' => $rotation, |
---|
[9191] | 338 | ); |
---|
[12917] | 339 | |
---|
[9191] | 340 | if (isset($level)) |
---|
| 341 | { |
---|
| 342 | $update['level'] = $level; |
---|
| 343 | } |
---|
| 344 | |
---|
[12879] | 345 | single_update( |
---|
[9191] | 346 | IMAGES_TABLE, |
---|
[12879] | 347 | $update, |
---|
| 348 | array('id' => $image_id) |
---|
[9191] | 349 | ); |
---|
| 350 | } |
---|
| 351 | else |
---|
[5089] | 352 | { |
---|
[9191] | 353 | // database registration |
---|
[13082] | 354 | $file = pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)); |
---|
[9191] | 355 | $insert = array( |
---|
[13082] | 356 | 'file' => $file, |
---|
| 357 | 'name' => get_name_from_file($file), |
---|
[9191] | 358 | 'date_available' => $dbnow, |
---|
| 359 | 'path' => preg_replace('#^'.preg_quote(PHPWG_ROOT_PATH).'#', '', $file_path), |
---|
| 360 | 'filesize' => $file_infos['filesize'], |
---|
| 361 | 'width' => $file_infos['width'], |
---|
| 362 | 'height' => $file_infos['height'], |
---|
| 363 | 'md5sum' => $md5sum, |
---|
| 364 | 'added_by' => $user['id'], |
---|
[13843] | 365 | 'rotation' => $rotation, |
---|
[9191] | 366 | ); |
---|
[12917] | 367 | |
---|
[9191] | 368 | if (isset($level)) |
---|
| 369 | { |
---|
| 370 | $insert['level'] = $level; |
---|
| 371 | } |
---|
[12879] | 372 | |
---|
[25929] | 373 | if (isset($representative_ext)) |
---|
| 374 | { |
---|
| 375 | $insert['representative_ext'] = $representative_ext; |
---|
| 376 | } |
---|
| 377 | |
---|
[12879] | 378 | single_insert(IMAGES_TABLE, $insert); |
---|
[12917] | 379 | |
---|
[9191] | 380 | $image_id = pwg_db_insert_id(IMAGES_TABLE); |
---|
| 381 | } |
---|
[5089] | 382 | |
---|
| 383 | if (isset($categories) and count($categories) > 0) |
---|
| 384 | { |
---|
| 385 | associate_images_to_categories( |
---|
| 386 | array($image_id), |
---|
| 387 | $categories |
---|
| 388 | ); |
---|
| 389 | } |
---|
[12917] | 390 | |
---|
[5089] | 391 | // update metadata from the uploaded file (exif/iptc) |
---|
[6622] | 392 | if ($conf['use_exif'] and !function_exists('read_exif_data')) |
---|
| 393 | { |
---|
| 394 | $conf['use_exif'] = false; |
---|
| 395 | } |
---|
[12831] | 396 | sync_metadata(array($image_id)); |
---|
[9191] | 397 | |
---|
[5089] | 398 | invalidate_user_cache(); |
---|
| 399 | |
---|
[13030] | 400 | // cache thumbnail |
---|
| 401 | $query = ' |
---|
| 402 | SELECT |
---|
| 403 | id, |
---|
| 404 | path |
---|
| 405 | FROM '.IMAGES_TABLE.' |
---|
| 406 | WHERE id = '.$image_id.' |
---|
| 407 | ;'; |
---|
| 408 | $image_infos = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 409 | |
---|
| 410 | set_make_full_url(); |
---|
| 411 | // in case we are on uploadify.php, we have to replace the false path |
---|
| 412 | $thumb_url = preg_replace('#admin/include/i#', 'i', DerivativeImage::thumb_url($image_infos)); |
---|
| 413 | unset_make_full_url(); |
---|
| 414 | |
---|
| 415 | fetchRemote($thumb_url, $dest); |
---|
| 416 | |
---|
| 417 | |
---|
[5089] | 418 | return $image_id; |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | function prepare_directory($directory) |
---|
| 422 | { |
---|
| 423 | if (!is_dir($directory)) { |
---|
[6385] | 424 | if (substr(PHP_OS, 0, 3) == 'WIN') |
---|
| 425 | { |
---|
| 426 | $directory = str_replace('/', DIRECTORY_SEPARATOR, $directory); |
---|
| 427 | } |
---|
[5089] | 428 | umask(0000); |
---|
| 429 | $recursive = true; |
---|
| 430 | if (!@mkdir($directory, 0777, $recursive)) |
---|
| 431 | { |
---|
| 432 | die('[prepare_directory] cannot create directory "'.$directory.'"'); |
---|
| 433 | } |
---|
| 434 | } |
---|
| 435 | |
---|
| 436 | if (!is_writable($directory)) |
---|
| 437 | { |
---|
| 438 | // last chance to make the directory writable |
---|
| 439 | @chmod($directory, 0777); |
---|
| 440 | |
---|
| 441 | if (!is_writable($directory)) |
---|
| 442 | { |
---|
| 443 | die('[prepare_directory] directory "'.$directory.'" has no write access'); |
---|
| 444 | } |
---|
| 445 | } |
---|
| 446 | |
---|
| 447 | secure_directory($directory); |
---|
| 448 | } |
---|
| 449 | |
---|
| 450 | function need_resize($image_filepath, $max_width, $max_height) |
---|
| 451 | { |
---|
[7868] | 452 | // TODO : the resize check should take the orientation into account. If a |
---|
| 453 | // rotation must be applied to the resized photo, then we should test |
---|
| 454 | // invert width and height. |
---|
[5089] | 455 | list($width, $height) = getimagesize($image_filepath); |
---|
[12917] | 456 | |
---|
[5089] | 457 | if ($width > $max_width or $height > $max_height) |
---|
| 458 | { |
---|
| 459 | return true; |
---|
| 460 | } |
---|
| 461 | |
---|
| 462 | return false; |
---|
| 463 | } |
---|
| 464 | |
---|
| 465 | function pwg_image_infos($path) |
---|
| 466 | { |
---|
| 467 | list($width, $height) = getimagesize($path); |
---|
| 468 | $filesize = floor(filesize($path)/1024); |
---|
[12917] | 469 | |
---|
[5089] | 470 | return array( |
---|
| 471 | 'width' => $width, |
---|
| 472 | 'height' => $height, |
---|
| 473 | 'filesize' => $filesize, |
---|
| 474 | ); |
---|
| 475 | } |
---|
| 476 | |
---|
| 477 | function is_valid_image_extension($extension) |
---|
| 478 | { |
---|
[9952] | 479 | return in_array(strtolower($extension), array('jpg', 'jpeg', 'png', 'gif')); |
---|
[5089] | 480 | } |
---|
[6625] | 481 | |
---|
| 482 | function file_upload_error_message($error_code) |
---|
| 483 | { |
---|
| 484 | switch ($error_code) { |
---|
| 485 | case UPLOAD_ERR_INI_SIZE: |
---|
| 486 | return sprintf( |
---|
| 487 | l10n('The uploaded file exceeds the upload_max_filesize directive in php.ini: %sB'), |
---|
| 488 | get_ini_size('upload_max_filesize', false) |
---|
| 489 | ); |
---|
| 490 | case UPLOAD_ERR_FORM_SIZE: |
---|
| 491 | return l10n('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'); |
---|
| 492 | case UPLOAD_ERR_PARTIAL: |
---|
| 493 | return l10n('The uploaded file was only partially uploaded'); |
---|
| 494 | case UPLOAD_ERR_NO_FILE: |
---|
| 495 | return l10n('No file was uploaded'); |
---|
| 496 | case UPLOAD_ERR_NO_TMP_DIR: |
---|
| 497 | return l10n('Missing a temporary folder'); |
---|
| 498 | case UPLOAD_ERR_CANT_WRITE: |
---|
| 499 | return l10n('Failed to write file to disk'); |
---|
| 500 | case UPLOAD_ERR_EXTENSION: |
---|
| 501 | return l10n('File upload stopped by extension'); |
---|
| 502 | default: |
---|
| 503 | return l10n('Unknown upload error'); |
---|
| 504 | } |
---|
| 505 | } |
---|
| 506 | |
---|
| 507 | function get_ini_size($ini_key, $in_bytes=true) |
---|
| 508 | { |
---|
| 509 | $size = ini_get($ini_key); |
---|
| 510 | |
---|
| 511 | if ($in_bytes) |
---|
| 512 | { |
---|
[10858] | 513 | $size = convert_shorthand_notation_to_bytes($size); |
---|
[6625] | 514 | } |
---|
[12917] | 515 | |
---|
[6625] | 516 | return $size; |
---|
| 517 | } |
---|
| 518 | |
---|
[10858] | 519 | function convert_shorthand_notation_to_bytes($value) |
---|
[6625] | 520 | { |
---|
| 521 | $suffix = substr($value, -1); |
---|
| 522 | $multiply_by = null; |
---|
[12917] | 523 | |
---|
[6625] | 524 | if ('K' == $suffix) |
---|
| 525 | { |
---|
| 526 | $multiply_by = 1024; |
---|
| 527 | } |
---|
| 528 | else if ('M' == $suffix) |
---|
| 529 | { |
---|
| 530 | $multiply_by = 1024*1024; |
---|
| 531 | } |
---|
| 532 | else if ('G' == $suffix) |
---|
| 533 | { |
---|
| 534 | $multiply_by = 1024*1024*1024; |
---|
| 535 | } |
---|
[12917] | 536 | |
---|
[6625] | 537 | if (isset($multiply_by)) |
---|
| 538 | { |
---|
| 539 | $value = substr($value, 0, -1); |
---|
| 540 | $value*= $multiply_by; |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | return $value; |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | function add_upload_error($upload_id, $error_message) |
---|
| 547 | { |
---|
[25018] | 548 | $_SESSION['uploads_error'][$upload_id][] = $error_message; |
---|
[6625] | 549 | } |
---|
[8227] | 550 | |
---|
[8249] | 551 | function ready_for_upload_message() |
---|
| 552 | { |
---|
| 553 | global $conf; |
---|
| 554 | |
---|
| 555 | $relative_dir = preg_replace('#^'.PHPWG_ROOT_PATH.'#', '', $conf['upload_dir']); |
---|
| 556 | |
---|
| 557 | if (!is_dir($conf['upload_dir'])) |
---|
| 558 | { |
---|
| 559 | if (!is_writable(dirname($conf['upload_dir']))) |
---|
| 560 | { |
---|
| 561 | return sprintf( |
---|
| 562 | l10n('Create the "%s" directory at the root of your Piwigo installation'), |
---|
| 563 | $relative_dir |
---|
| 564 | ); |
---|
| 565 | } |
---|
| 566 | } |
---|
| 567 | else |
---|
| 568 | { |
---|
| 569 | if (!is_writable($conf['upload_dir'])) |
---|
| 570 | { |
---|
| 571 | @chmod($conf['upload_dir'], 0777); |
---|
[12917] | 572 | |
---|
[8249] | 573 | if (!is_writable($conf['upload_dir'])) |
---|
| 574 | { |
---|
| 575 | return sprintf( |
---|
| 576 | l10n('Give write access (chmod 777) to "%s" directory at the root of your Piwigo installation'), |
---|
| 577 | $relative_dir |
---|
| 578 | ); |
---|
| 579 | } |
---|
| 580 | } |
---|
| 581 | } |
---|
| 582 | |
---|
| 583 | return null; |
---|
| 584 | } |
---|
[5089] | 585 | ?> |
---|