Changeset 37 for trunk/lib/Upload.inc.php
- Timestamp:
- Dec 14, 2005 7:07:43 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Upload.inc.php
r36 r37 8 8 * @author Quinn Comendant <quinn@strangecode.com> 9 9 * @requires App.inc.php 10 * @version 1. 210 * @version 1.3 11 11 */ 12 13 // Message Types. 14 define('UPLOAD_MSG_ERR', MSG_ERR); 15 define('UPLOAD_MSG_ERROR', MSG_ERROR); 16 define('UPLOAD_MSG_WARNING', MSG_WARNING); 17 define('UPLOAD_MSG_NOTICE', MSG_NOTICE); 18 define('UPLOAD_MSG_SUCCESS', MSG_SUCCESS); 19 define('UPLOAD_MSG_ALL', MSG_SUCCESS + MSG_NOTICE + MSG_WARNING + MSG_ERROR); 12 20 13 21 require_once dirname(__FILE__) . '/App.inc.php'; … … 18 26 var $_params = array( 19 27 20 // Display message withraiseMsg?21 'display_messages' => true,28 // Which messages do we pass to raiseMsg? 29 'display_messages' => UPLOAD_MSG_ALL, 22 30 23 31 // Existing files will be overwritten when there is a name conflict? … … 267 275 268 276 /** 269 * 277 * Process uploaded files. Processes files existing within the specified $_FILES['form_name'] array. 278 * It tests for errors, cleans the filename, optionally sets custom file names. It will process 279 * multiple files automatically if the file form element is an array (<input type="file" name="myfiles[]" />). 280 * 281 * @access public 282 * @param string $form_name The name of the form to process. 283 * @param string $custom_file_name The new name of the file. does not work if processing multiple files. 284 * @return mixed Returns FALSE if a major error occured preventing any file uploads. 285 * Returns an empty array if any minor errors occured or no files were found. 286 * Returns a multidimentional array of filenames, sizes and extentions, if one-or-more files succeeded uploading. 287 * Note: this last option presents a problem in the case of when some files uploaded successfully, and some failed. 288 * In this case it is necessary to check the Upload::anyErrors method to discover if any did fail. 270 289 */ 271 290 function process($form_name, $custom_file_name=null) … … 448 467 449 468 /** 450 * 469 * Remove file within upload path. 470 * 471 * @access public 472 * @param string $file_name A name of a file. 473 * @return bool Success of operation. 451 474 */ 452 475 function deleteFile($file_name) … … 466 489 App::logMsg(sprintf('Deleted file: %s', $file_path_name), LOG_DEBUG, __FILE__, __LINE__); 467 490 } else { 468 $this->raiseMsg(sprintf(_("The file <strong>%s</strong> could not be deleted."), $file_name), MSG_ERR OR, __FILE__, __LINE__);491 $this->raiseMsg(sprintf(_("The file <strong>%s</strong> could not be deleted."), $file_name), MSG_ERR, __FILE__, __LINE__); 469 492 App::logMsg(sprintf(_("Failed deleting file: %s"), $file_path_name), LOG_ERR, __FILE__, __LINE__); 470 493 return false; … … 473 496 474 497 /** 475 * 498 * Renames a file within the upload path. 499 * 500 * @access public 501 * @param string $old_name The currently existing file name. 502 * @param string $new_name The new name for this file. 503 * @return bool Success of operation. 476 504 */ 477 505 function moveFile($old_name, $new_name) … … 490 518 App::logMsg(sprintf('File renamed from %s to %s', $old_file_path_name, $new_file_path_name), LOG_DEBUG, __FILE__, __LINE__); 491 519 } else { 492 $this->raiseMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), MSG_ ERR, __FILE__, __LINE__);493 App::logMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), LOG_ ERR, __FILE__, __LINE__);520 $this->raiseMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), MSG_WARNING, __FILE__, __LINE__); 521 App::logMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), LOG_WARNING, __FILE__, __LINE__); 494 522 return false; 495 523 } 496 524 } else { 497 $this->raiseMsg(sprintf(_("Couldn't rename nonexistent file <strong>%s</strong>."), $old_name), MSG_ ERR, __FILE__, __LINE__);498 App::logMsg(sprintf(_("Error renaming nonexistent file: %s"), $old_file_path_name), LOG_ ERR, __FILE__, __LINE__);525 $this->raiseMsg(sprintf(_("Couldn't rename nonexistent file <strong>%s</strong>."), $old_name), MSG_WARNING, __FILE__, __LINE__); 526 App::logMsg(sprintf(_("Error renaming nonexistent file: %s"), $old_file_path_name), LOG_WARNING, __FILE__, __LINE__); 499 527 return false; 500 528 } … … 502 530 503 531 /** 504 * 532 * Tests if a file exists within the current upload_path. 533 * 534 * @access public 535 * @param string $file_name A name of a file. 536 * @return bool Existence of file. 505 537 */ 506 538 function exists($file_name) … … 536 568 537 569 /** 538 * 570 * Returns an array of file names that failed uploading. 571 * 572 * @access public 573 * @return array List of file names. 539 574 */ 540 575 function getErrors() … … 544 579 545 580 /** 546 * 581 * Determintes if any errors occured while calling the Upload::process method. 582 * 583 * @access public 547 584 */ 548 585 function anyErrors() … … 552 589 553 590 /** 554 * 591 * Removes unsafe characters from file name. 592 * 593 * @access public 594 * @param string $file_name A name of a file. 595 * @return string The same name, but cleaned. 555 596 */ 556 597 function cleanFileName($file_name) … … 565 606 } 566 607 567 /** 568 * 608 609 /** 610 * Returns the extention of a file name, or an empty string if non exists. 611 * 612 * @access public 613 * @param string $file_name A name of a file, with extention after a dot. 614 * @return string The value found after the dot 569 615 */ 570 616 function getFilenameExtension($file_name) 571 617 { 572 preg_match('/.*?\.(\w+)$/i', $file_name, $ext);618 preg_match('/.*?\.(\w+)$/i', trim($file_name), $ext); 573 619 return isset($ext[1]) ? $ext[1] : ''; 574 620 } 575 621 576 622 /** 577 * An alias for App::raiseMsg that only sends messages if display_messages is true.623 * An alias for App::raiseMsg that only sends messages configured by display_messages. 578 624 * 579 625 * @access public … … 587 633 function raiseMsg($message, $type, $file, $line) 588 634 { 589 if ($this->getParam('display_messages') ) {635 if ($this->getParam('display_messages') === true || (is_int($this->getParam('display_messages')) && $this->getParam('display_messages') >= $type)) { 590 636 App::raiseMsg($message, $type, $file, $line); 591 637 }
Note: See TracChangeset
for help on using the changeset viewer.