Changeset 105 for branches/1.1dev/lib
- Timestamp:
- Apr 20, 2006 3:30:23 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.1dev/lib/Upload.inc.php
r104 r105 17 17 class Upload { 18 18 19 // General object parameters.20 var $ _params = array(21 'display_messages' => true,22 'allow_overwriting' => false,23 );19 // Display error messages to the user? 20 var $display_messages = true; 21 22 // Existing files with the same name will be overwritten? 23 var $allow_overwriting = false; 24 24 25 25 // Disk path where new image(s) will be uploaded. … … 213 213 'zip' => 'application/zip' 214 214 ); 215 216 /**217 * Set (or overwrite existing) parameters by passing an array of new parameters.218 *219 * @access public220 *221 * @param array $params Array of parameters (key => val pairs).222 */223 function setParam($params=null)224 {225 if (isset($params) && is_array($params)) {226 // Set parameters for this object.227 $this->_params = array_merge($this->_params, $params);228 }229 }230 231 /**232 * Return the value of a parameter.233 *234 * @access public235 *236 * @param string $param The key of the parameter to return.237 *238 * @return mixed Parameter value.239 */240 function getParam($param)241 {242 return $this->_params[$param];243 }244 215 245 216 /** … … 269 240 if (!isset($this->upload_directory_path)) { 270 241 logMsg(sprintf('Upload directory not set before processing.'), LOG_ERR, __FILE__, __LINE__); 271 if ($this-> getParam('display_messages')) {242 if ($this->display_messages) { 272 243 raiseMsg(_("There was a problem with the file upload. Please try again later."), MSG_ERR, __FILE__, __LINE__); 273 244 } … … 277 248 if (!isset($_FILES[$form_name])) { 278 249 logMsg(sprintf(_("Form element %s not posted."), $form_name), LOG_ERR, __FILE__, __LINE__); 279 if ($this-> getParam('display_messages')) {250 if ($this->display_messages) { 280 251 raiseMsg(_("There was a problem with the file upload. Please try again."), MSG_ERR, __FILE__, __LINE__); 281 252 } … … 308 279 $file_path_name = ''; 309 280 310 if ('' == trim($files[' tmp_name'][$i])) {281 if ('' == trim($files['name'][$i])) { 311 282 // User may not have attached a file. 312 283 continue; … … 315 286 // Check The php upload error messages. 316 287 if (UPLOAD_ERR_INI_SIZE === $files['error'][$i]) { 317 if ($this-> getParam('display_messages')) {288 if ($this->display_messages) { 318 289 raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it exceeds the maximum allowed upload filesize of %s."), $files['name'][$i], ini_get('upload_max_filesize')), MSG_ERR, __FILE__, __LINE__); 319 290 } … … 323 294 } 324 295 if (UPLOAD_ERR_FORM_SIZE === $files['error'][$i]) { 325 if ($this-> getParam('display_messages')) {296 if ($this->display_messages) { 326 297 raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it exceeds the maximum allowed upload filesize of %s."), $files['name'][$i], $_POST['MAX_FILE_SIZE']), MSG_ERR, __FILE__, __LINE__); 327 298 } … … 331 302 } 332 303 if (UPLOAD_ERR_PARTIAL === $files['error'][$i]) { 333 if ($this-> getParam('display_messages')) {304 if ($this->display_messages) { 334 305 raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it was only partially uploaded."), $files['name'][$i]), MSG_ERR, __FILE__, __LINE__); 335 306 } … … 339 310 } 340 311 if (UPLOAD_ERR_NO_FILE === $files['error'][$i]) { 341 if ($this-> getParam('display_messages')) {312 if ($this->display_messages) { 342 313 raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: no file was uploaded."), $files['name'][$i]), MSG_ERR, __FILE__, __LINE__); 343 314 } … … 347 318 } 348 319 if (UPLOAD_ERR_NO_TMP_DIR === $files['error'][$i]) { 349 if ($this-> getParam('display_messages')) {320 if ($this->display_messages) { 350 321 raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: temporary upload directory missing."), $files['name'][$i]), MSG_ERR, __FILE__, __LINE__); 351 322 } … … 357 328 // Check to be sure it's an uploaded file. 358 329 if (!is_uploaded_file($files['tmp_name'][$i])) { 359 if ($this-> getParam('display_messages')) {330 if ($this->display_messages) { 360 331 raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading."), $files['name'][$i]), MSG_ERR, __FILE__, __LINE__); 361 332 } … … 367 338 // Check to be sure the file is not empty. 368 339 if ($files['size'][$i] < 1) { 369 if ($this-> getParam('display_messages')) {340 if ($this->display_messages) { 370 341 raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it contains zero bytes."), $files['name'][$i]), MSG_ERR, __FILE__, __LINE__); 371 342 } … … 377 348 // Check to be sure the file has a valid file extension. 378 349 if (!in_array(strtolower($this->getFilenameExtension($files['name'][$i])), $this->valid_file_extensions)) { 379 if ($this-> getParam('display_messages')) {350 if ($this->display_messages) { 380 351 raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it is an unrecognised type. Files must have one of the following file extensions: %s."), $files['name'][$i], join(', ', $this->valid_file_extensions)), MSG_ERR, __FILE__, __LINE__); 381 352 } … … 386 357 387 358 // Check to be sure the file has a unique file name. 388 if (!$this-> getParam('allow_overwriting')&& $this->exists($files['name'][$i])) {389 if ($this-> getParam('display_messages')) {359 if (!$this->allow_overwriting && $this->exists($files['name'][$i])) { 360 if ($this->display_messages) { 390 361 raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: a file with that name already exists."), $files['name'][$i]), MSG_ERR, __FILE__, __LINE__); 391 362 } … … 401 372 // Valid custom file name. 402 373 $file_name = $custom_file_name; 403 if ($this-> getParam('display_messages')) {374 if ($this->display_messages) { 404 375 raiseMsg(sprintf(_("The file <strong>%s</strong> has been renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__); 405 376 } … … 415 386 // Valid custom file name. 416 387 $file_name = $custom_file_name[$i]; 417 if ($this-> getParam('display_messages')) {388 if ($this->display_messages) { 418 389 raiseMsg(sprintf(_("The file <strong>%s</strong> has been renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__); 419 390 } … … 442 413 if (move_uploaded_file($files['tmp_name'][$i], $file_path_name)) { 443 414 chmod($file_path_name, $this->dest_file_perms); 444 if ($this-> getParam('display_messages')) {415 if ($this->display_messages) { 445 416 raiseMsg(sprintf(_("The file <strong>%s</strong> uploaded successfully."), $files['name'][$i]), MSG_SUCCESS, __FILE__, __LINE__); 446 417 } 447 418 if (!isset($custom_file_name) && $files['name'][$i] != $file_name) { 448 419 // Notify user if uploaded file name was modified (unless a custom file name will be used anyways). 449 if ($this-> getParam('display_messages')) {420 if ($this->display_messages) { 450 421 raiseMsg(sprintf(_("The file <strong>%s</strong> was renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__); 422 logMsg(sprintf('File successfully renamed: %s -> %s', $files['tmp_name'][$i], $file_path_name), LOG_DEBUG, __FILE__, __LINE__); 451 423 } 452 424 } … … 458 430 continue; 459 431 } else { 460 if ($this-> getParam('display_messages')) {432 if ($this->display_messages) { 461 433 raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading."), $files['name'][$i]), MSG_ERR, __FILE__, __LINE__); 462 434 } … … 488 460 logMsg(sprintf('Deleted file: %s', $file_path_name), LOG_DEBUG, __FILE__, __LINE__); 489 461 } else { 490 if ($this-> getParam('display_messages')) {462 if ($this->display_messages) { 491 463 raiseMsg(sprintf(_("The file <strong>%s</strong> could not be deleted."), $file_name), MSG_ERROR, __FILE__, __LINE__); 492 464 } … … 511 483 if (file_exists($old_file_path_name)) { 512 484 if (!rename($old_file_path_name, $new_file_path_name)) { 513 if ($this-> getParam('display_messages')) {485 if ($this->display_messages) { 514 486 raiseMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), MSG_ERR, __FILE__, __LINE__); 515 487 } … … 518 490 } 519 491 } else { 520 if ($this-> getParam('display_messages')) {492 if ($this->display_messages) { 521 493 raiseMsg(sprintf(_("Couldn't rename nonexistant file <strong>%s</strong>."), $old_name), MSG_ERR, __FILE__, __LINE__); 522 494 } … … 553 525 function cleanFileName($file_name) 554 526 { 555 $bad = 'çêîòËéíñôèì 556 åæëïó@'; 527 $bad = 'áéÃóúà ÚìòùÀëïöÌÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃâêîÎûÃÃÃÃÃñçÃ@'; 557 528 $good = 'aeiouaeiouaeiouAEIOUAEIOUAEIOUaeiouAEIOUncCa'; 558 529 $file_name = trim($file_name);
Note: See TracChangeset
for help on using the changeset viewer.