@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @package FileUpload |
| 38 | 38 | * @version 1.5 |
| 39 | 39 | */ |
| 40 | - class Upload{ |
|
| 40 | + class Upload { |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Version |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @version 1.0 |
| 70 | 70 | * @var array |
| 71 | 71 | */ |
| 72 | - private $file_array = array(); |
|
| 72 | + private $file_array = array(); |
|
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * If the file you are trying to upload already exists it will |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @version 1.0 |
| 120 | 120 | * @var float |
| 121 | 121 | */ |
| 122 | - private $max_file_size= 0.0; |
|
| 122 | + private $max_file_size = 0.0; |
|
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * List of allowed mime types |
@@ -217,12 +217,12 @@ discard block |
||
| 217 | 217 | * @return object |
| 218 | 218 | * @method object __construct |
| 219 | 219 | */ |
| 220 | - public function __construct(){ |
|
| 221 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 220 | + public function __construct() { |
|
| 221 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 222 | 222 | $this->logger->setLogger('Library::Upload'); |
| 223 | 223 | |
| 224 | 224 | Loader::lang('file_upload'); |
| 225 | - $obj =& get_instance(); |
|
| 225 | + $obj = & get_instance(); |
|
| 226 | 226 | |
| 227 | 227 | $this->error_messages = array( |
| 228 | 228 | 'upload_err_ini_size' => $obj->lang->get('fu_upload_err_ini_size'), |
@@ -239,15 +239,15 @@ discard block |
||
| 239 | 239 | ); |
| 240 | 240 | |
| 241 | 241 | $this->file = array( |
| 242 | - 'status' => false, // True: success upload |
|
| 243 | - 'mime' => '', // Empty string |
|
| 244 | - 'filename' => '', // Empty string |
|
| 245 | - 'original' => '', // Empty string |
|
| 246 | - 'size' => 0, // 0 Bytes |
|
| 247 | - 'sizeFormated' => '0B', // 0 Bytes |
|
| 248 | - 'destination' => './', // Default: ./ |
|
| 249 | - 'allowed_mime_types' => array(), // Allowed mime types |
|
| 250 | - 'error' => null, // File error |
|
| 242 | + 'status' => false, // True: success upload |
|
| 243 | + 'mime' => '', // Empty string |
|
| 244 | + 'filename' => '', // Empty string |
|
| 245 | + 'original' => '', // Empty string |
|
| 246 | + 'size' => 0, // 0 Bytes |
|
| 247 | + 'sizeFormated' => '0B', // 0 Bytes |
|
| 248 | + 'destination' => './', // Default: ./ |
|
| 249 | + 'allowed_mime_types' => array(), // Allowed mime types |
|
| 250 | + 'error' => null, // File error |
|
| 251 | 251 | ); |
| 252 | 252 | |
| 253 | 253 | // Change dir to current dir |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | if (isset($_FILES) && is_array($_FILES)) { |
| 258 | 258 | $this->file_array = $_FILES; |
| 259 | 259 | } |
| 260 | - $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array)); |
|
| 260 | + $this->logger->info('The upload file information are : ' . stringfy_vars($this->file_array)); |
|
| 261 | 261 | } |
| 262 | 262 | /** |
| 263 | 263 | * Set input. |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | */ |
| 274 | 274 | public function setInput($input) |
| 275 | 275 | { |
| 276 | - if (!empty($input) && (is_string($input) || is_numeric($input) )) { |
|
| 276 | + if (!empty($input) && (is_string($input) || is_numeric($input))) { |
|
| 277 | 277 | $this->input = $input; |
| 278 | 278 | } |
| 279 | 279 | return $this; |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | */ |
| 310 | 310 | public function setAutoFilename() |
| 311 | 311 | { |
| 312 | - $this->filename = sha1(mt_rand(1, 9999).uniqid()); |
|
| 312 | + $this->filename = sha1(mt_rand(1, 9999) . uniqid()); |
|
| 313 | 313 | $this->filename .= time(); |
| 314 | 314 | return $this; |
| 315 | 315 | } |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | $php_size = $this->sizeInBytes((int) ini_get('upload_max_filesize')); |
| 331 | 331 | // Calculate difference |
| 332 | 332 | if ($php_size < $file_size) { |
| 333 | - $this->logger->warning('The upload max file size you set [' .$file_size. '] is greather than the PHP configuration for upload max file size [' .$php_size. ']'); |
|
| 333 | + $this->logger->warning('The upload max file size you set [' . $file_size . '] is greather than the PHP configuration for upload max file size [' . $php_size . ']'); |
|
| 334 | 334 | } |
| 335 | 335 | $this->max_file_size = $file_size; |
| 336 | 336 | } |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | public function setAllowedMimeTypes(array $mimes) |
| 349 | 349 | { |
| 350 | 350 | if (count($mimes) > 0) { |
| 351 | - array_map(array($this , 'setAllowMimeType'), $mimes); |
|
| 351 | + array_map(array($this, 'setAllowMimeType'), $mimes); |
|
| 352 | 352 | } |
| 353 | 353 | return $this; |
| 354 | 354 | } |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | { |
| 414 | 414 | if (!empty($name) && is_string($name)) { |
| 415 | 415 | if (array_key_exists($name, $this->mime_helping)) { |
| 416 | - return $this->setAllowedMimeTypes($this->mime_helping[ $name ]); |
|
| 416 | + return $this->setAllowedMimeTypes($this->mime_helping[$name]); |
|
| 417 | 417 | } |
| 418 | 418 | } |
| 419 | 419 | return $this; |
@@ -432,8 +432,8 @@ discard block |
||
| 432 | 432 | */ |
| 433 | 433 | public function setUploadFunction($function) |
| 434 | 434 | { |
| 435 | - if (!empty($function) && (is_array($function) || is_string($function) )) { |
|
| 436 | - if (is_callable( $function)) { |
|
| 435 | + if (!empty($function) && (is_array($function) || is_string($function))) { |
|
| 436 | + if (is_callable($function)) { |
|
| 437 | 437 | $this->upload_function = $function; |
| 438 | 438 | } |
| 439 | 439 | } |
@@ -478,8 +478,8 @@ discard block |
||
| 478 | 478 | $this->destination_directory = $destination_directory; |
| 479 | 479 | chdir($destination_directory); |
| 480 | 480 | } |
| 481 | - else{ |
|
| 482 | - $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']'); |
|
| 481 | + else { |
|
| 482 | + $this->logger->warning('Can not create the upload directory [' . $destination_directory . ']'); |
|
| 483 | 483 | } |
| 484 | 484 | } |
| 485 | 485 | } |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | public function isFilename($filename) |
| 530 | 530 | { |
| 531 | 531 | $filename = basename($filename); |
| 532 | - return (!empty($filename) && (is_string( $filename) || is_numeric($filename))); |
|
| 532 | + return (!empty($filename) && (is_string($filename) || is_numeric($filename))); |
|
| 533 | 533 | } |
| 534 | 534 | /** |
| 535 | 535 | * Validate mime type with allowed mime types, |
@@ -571,11 +571,11 @@ discard block |
||
| 571 | 571 | */ |
| 572 | 572 | public function isDirpath($path) |
| 573 | 573 | { |
| 574 | - if (!empty( $path) && (is_string( $path) || is_numeric($path) )) { |
|
| 574 | + if (!empty($path) && (is_string($path) || is_numeric($path))) { |
|
| 575 | 575 | if (DIRECTORY_SEPARATOR == '/') { |
| 576 | - return (preg_match( '/^[^*?"<>|:]*$/' , $path) == 1 ); |
|
| 576 | + return (preg_match('/^[^*?"<>|:]*$/', $path) == 1); |
|
| 577 | 577 | } else { |
| 578 | - return (preg_match( "/^[^*?\"<>|:]*$/" , substr($path,2) ) == 1); |
|
| 578 | + return (preg_match("/^[^*?\"<>|:]*$/", substr($path, 2)) == 1); |
|
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | return false; |
@@ -603,7 +603,7 @@ discard block |
||
| 603 | 603 | */ |
| 604 | 604 | public function getInfo() |
| 605 | 605 | { |
| 606 | - return (object)$this->file; |
|
| 606 | + return (object) $this->file; |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | * Check if the file is uploaded |
| 612 | 612 | * @return boolean |
| 613 | 613 | */ |
| 614 | - public function isUploaded(){ |
|
| 614 | + public function isUploaded() { |
|
| 615 | 615 | return isset($this->file_array[$this->input]) |
| 616 | 616 | && is_uploaded_file($this->file_array[$this->input]['tmp_name']); |
| 617 | 617 | } |
@@ -625,13 +625,13 @@ discard block |
||
| 625 | 625 | * @return boolean |
| 626 | 626 | * @method boolean save |
| 627 | 627 | */ |
| 628 | - public function save(){ |
|
| 628 | + public function save() { |
|
| 629 | 629 | if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) { |
| 630 | 630 | // set original filename if not have a new name |
| 631 | 631 | if (empty($this->filename)) { |
| 632 | 632 | $this->filename = $this->file_array[$this->input]['name']; |
| 633 | 633 | } |
| 634 | - else{ |
|
| 634 | + else { |
|
| 635 | 635 | // Replace %s for extension in filename |
| 636 | 636 | // Before: /[\w\d]*(.[\d\w]+)$/i |
| 637 | 637 | // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu |
@@ -655,10 +655,10 @@ discard block |
||
| 655 | 655 | $this->file['filename'] = $this->filename; |
| 656 | 656 | $this->file['error'] = $this->file_array[$this->input]['error']; |
| 657 | 657 | |
| 658 | - $this->logger->info('The upload file information to process is : ' .stringfy_vars($this->file)); |
|
| 658 | + $this->logger->info('The upload file information to process is : ' . stringfy_vars($this->file)); |
|
| 659 | 659 | |
| 660 | 660 | $error = $this->uploadHasError(); |
| 661 | - if($error){ |
|
| 661 | + if ($error) { |
|
| 662 | 662 | return false; |
| 663 | 663 | } |
| 664 | 664 | // Execute input callback |
@@ -692,10 +692,10 @@ discard block |
||
| 692 | 692 | */ |
| 693 | 693 | public function sizeFormat($size, $precision = 2) |
| 694 | 694 | { |
| 695 | - if($size > 0){ |
|
| 695 | + if ($size > 0) { |
|
| 696 | 696 | $base = log($size) / log(1024); |
| 697 | 697 | $suffixes = array('B', 'K', 'M', 'G', 'T'); |
| 698 | - return round(pow(1024, $base - floor($base)), $precision) . ( isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : ''); |
|
| 698 | + return round(pow(1024, $base - floor($base)), $precision) . (isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : ''); |
|
| 699 | 699 | } |
| 700 | 700 | return null; |
| 701 | 701 | } |
@@ -719,14 +719,14 @@ discard block |
||
| 719 | 719 | if (array_key_exists('unit', $matches)) { |
| 720 | 720 | $unit = strtoupper($matches['unit']); |
| 721 | 721 | } |
| 722 | - return (floatval($matches['size']) * pow(1024, $units[$unit]) ) ; |
|
| 722 | + return (floatval($matches['size']) * pow(1024, $units[$unit])); |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | /** |
| 726 | 726 | * Get the upload error message |
| 727 | 727 | * @return string |
| 728 | 728 | */ |
| 729 | - public function getError(){ |
|
| 729 | + public function getError() { |
|
| 730 | 730 | return $this->error; |
| 731 | 731 | } |
| 732 | 732 | |
@@ -734,7 +734,7 @@ discard block |
||
| 734 | 734 | * Set the upload error message |
| 735 | 735 | * @param string $message the upload error message to set |
| 736 | 736 | */ |
| 737 | - public function setError($message){ |
|
| 737 | + public function setError($message) { |
|
| 738 | 738 | $this->logger->info('The file upload got error : ' . $message); |
| 739 | 739 | $this->error = $message; |
| 740 | 740 | } |
@@ -744,9 +744,9 @@ discard block |
||
| 744 | 744 | * @param string $type the type of callback "input" or "output" |
| 745 | 745 | * @return void |
| 746 | 746 | */ |
| 747 | - protected function runCallback($type){ |
|
| 748 | - if (!empty( $this->callbacks[$type])) { |
|
| 749 | - call_user_func($this->callbacks[$type], (object)$this->file); |
|
| 747 | + protected function runCallback($type) { |
|
| 748 | + if (!empty($this->callbacks[$type])) { |
|
| 749 | + call_user_func($this->callbacks[$type], (object) $this->file); |
|
| 750 | 750 | } |
| 751 | 751 | } |
| 752 | 752 | |
@@ -754,21 +754,21 @@ discard block |
||
| 754 | 754 | * Check if file upload has error |
| 755 | 755 | * @return boolean |
| 756 | 756 | */ |
| 757 | - protected function uploadHasError(){ |
|
| 757 | + protected function uploadHasError() { |
|
| 758 | 758 | //check if file upload is allowed in the configuration |
| 759 | - if(! ini_get('file_uploads')){ |
|
| 759 | + if (!ini_get('file_uploads')) { |
|
| 760 | 760 | $this->setError($this->error_messages['file_uploads']); |
| 761 | 761 | return true; |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | //check for php upload error |
| 765 | - if(is_numeric($this->file['error']) && $this->file['error'] > 0){ |
|
| 765 | + if (is_numeric($this->file['error']) && $this->file['error'] > 0) { |
|
| 766 | 766 | $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error'])); |
| 767 | 767 | return true; |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | //check for mime type |
| 771 | - if (! $this->checkMimeType($this->file['mime'])) { |
|
| 771 | + if (!$this->checkMimeType($this->file['mime'])) { |
|
| 772 | 772 | $this->setError($this->error_messages['accept_file_types']); |
| 773 | 773 | return true; |
| 774 | 774 | } |
@@ -792,7 +792,7 @@ discard block |
||
| 792 | 792 | * @param int $code the error code |
| 793 | 793 | * @return string the error message |
| 794 | 794 | */ |
| 795 | - private function getPhpUploadErrorMessageByCode($code){ |
|
| 795 | + private function getPhpUploadErrorMessageByCode($code) { |
|
| 796 | 796 | $codeMessageMaps = array( |
| 797 | 797 | 1 => $this->error_messages['upload_err_ini_size'], |
| 798 | 798 | 2 => $this->error_messages['upload_err_form_size'], |
@@ -477,8 +477,7 @@ discard block |
||
| 477 | 477 | if (mkdir($destination_directory, 0775, true)) { |
| 478 | 478 | $this->destination_directory = $destination_directory; |
| 479 | 479 | chdir($destination_directory); |
| 480 | - } |
|
| 481 | - else{ |
|
| 480 | + } else{ |
|
| 482 | 481 | $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']'); |
| 483 | 482 | } |
| 484 | 483 | } |
@@ -630,8 +629,7 @@ discard block |
||
| 630 | 629 | // set original filename if not have a new name |
| 631 | 630 | if (empty($this->filename)) { |
| 632 | 631 | $this->filename = $this->file_array[$this->input]['name']; |
| 633 | - } |
|
| 634 | - else{ |
|
| 632 | + } else{ |
|
| 635 | 633 | // Replace %s for extension in filename |
| 636 | 634 | // Before: /[\w\d]*(.[\d\w]+)$/i |
| 637 | 635 | // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu |
@@ -22,139 +22,139 @@ discard block |
||
| 22 | 22 | * You should have received a copy of the GNU General Public License |
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | - */ |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Upload |
|
| 31 | - * |
|
| 32 | - * A complete class to upload files with php 5 or higher, but the best: very simple to use. |
|
| 33 | - * |
|
| 34 | - * @author Olaf Erlandsen <[email protected]> |
|
| 35 | - * @author http://www.webdevfreelance.com/ |
|
| 36 | - * |
|
| 37 | - * @package FileUpload |
|
| 38 | - * @version 1.5 |
|
| 39 | - */ |
|
| 30 | + * Upload |
|
| 31 | + * |
|
| 32 | + * A complete class to upload files with php 5 or higher, but the best: very simple to use. |
|
| 33 | + * |
|
| 34 | + * @author Olaf Erlandsen <[email protected]> |
|
| 35 | + * @author http://www.webdevfreelance.com/ |
|
| 36 | + * |
|
| 37 | + * @package FileUpload |
|
| 38 | + * @version 1.5 |
|
| 39 | + */ |
|
| 40 | 40 | class Upload{ |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | - * Version |
|
| 44 | - * |
|
| 45 | - * @since 1.5 |
|
| 46 | - * @version 1.0 |
|
| 47 | - */ |
|
| 43 | + * Version |
|
| 44 | + * |
|
| 45 | + * @since 1.5 |
|
| 46 | + * @version 1.0 |
|
| 47 | + */ |
|
| 48 | 48 | const VERSION = '1.5'; |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | - * Upload function name |
|
| 52 | - * Remember: |
|
| 53 | - * Default function: move_uploaded_file |
|
| 54 | - * Native options: |
|
| 55 | - * - move_uploaded_file (Default and best option) |
|
| 56 | - * - copy |
|
| 57 | - * |
|
| 58 | - * @since 1.0 |
|
| 59 | - * @version 1.0 |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 51 | + * Upload function name |
|
| 52 | + * Remember: |
|
| 53 | + * Default function: move_uploaded_file |
|
| 54 | + * Native options: |
|
| 55 | + * - move_uploaded_file (Default and best option) |
|
| 56 | + * - copy |
|
| 57 | + * |
|
| 58 | + * @since 1.0 |
|
| 59 | + * @version 1.0 |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | 62 | private $upload_function = 'move_uploaded_file'; |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * Array with the information obtained from the |
|
| 66 | - * variable $_FILES or $HTTP_POST_FILES. |
|
| 67 | - * |
|
| 68 | - * @since 1.0 |
|
| 69 | - * @version 1.0 |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 65 | + * Array with the information obtained from the |
|
| 66 | + * variable $_FILES or $HTTP_POST_FILES. |
|
| 67 | + * |
|
| 68 | + * @since 1.0 |
|
| 69 | + * @version 1.0 |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | 72 | private $file_array = array(); |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | - * If the file you are trying to upload already exists it will |
|
| 76 | - * be overwritten if you set the variable to true. |
|
| 77 | - * |
|
| 78 | - * @since 1.0 |
|
| 79 | - * @version 1.0 |
|
| 80 | - * @var boolean |
|
| 81 | - */ |
|
| 75 | + * If the file you are trying to upload already exists it will |
|
| 76 | + * be overwritten if you set the variable to true. |
|
| 77 | + * |
|
| 78 | + * @since 1.0 |
|
| 79 | + * @version 1.0 |
|
| 80 | + * @var boolean |
|
| 81 | + */ |
|
| 82 | 82 | private $overwrite_file = false; |
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | - * Input element |
|
| 86 | - * Example: |
|
| 87 | - * <input type="file" name="file" /> |
|
| 88 | - * Result: |
|
| 89 | - * FileUpload::$input = file |
|
| 90 | - * |
|
| 91 | - * @since 1.0 |
|
| 92 | - * @version 1.0 |
|
| 93 | - * @var string |
|
| 94 | - */ |
|
| 85 | + * Input element |
|
| 86 | + * Example: |
|
| 87 | + * <input type="file" name="file" /> |
|
| 88 | + * Result: |
|
| 89 | + * FileUpload::$input = file |
|
| 90 | + * |
|
| 91 | + * @since 1.0 |
|
| 92 | + * @version 1.0 |
|
| 93 | + * @var string |
|
| 94 | + */ |
|
| 95 | 95 | private $input; |
| 96 | 96 | |
| 97 | 97 | /** |
| 98 | - * Path output |
|
| 99 | - * |
|
| 100 | - * @since 1.0 |
|
| 101 | - * @version 1.0 |
|
| 102 | - * @var string |
|
| 103 | - */ |
|
| 98 | + * Path output |
|
| 99 | + * |
|
| 100 | + * @since 1.0 |
|
| 101 | + * @version 1.0 |
|
| 102 | + * @var string |
|
| 103 | + */ |
|
| 104 | 104 | private $destination_directory; |
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | - * Output filename |
|
| 108 | - * |
|
| 109 | - * @since 1.0 |
|
| 110 | - * @version 1.0 |
|
| 111 | - * @var string |
|
| 112 | - */ |
|
| 107 | + * Output filename |
|
| 108 | + * |
|
| 109 | + * @since 1.0 |
|
| 110 | + * @version 1.0 |
|
| 111 | + * @var string |
|
| 112 | + */ |
|
| 113 | 113 | private $filename; |
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | - * Max file size |
|
| 117 | - * |
|
| 118 | - * @since 1.0 |
|
| 119 | - * @version 1.0 |
|
| 120 | - * @var float |
|
| 121 | - */ |
|
| 116 | + * Max file size |
|
| 117 | + * |
|
| 118 | + * @since 1.0 |
|
| 119 | + * @version 1.0 |
|
| 120 | + * @var float |
|
| 121 | + */ |
|
| 122 | 122 | private $max_file_size= 0.0; |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | - * List of allowed mime types |
|
| 126 | - * |
|
| 127 | - * @since 1.0 |
|
| 128 | - * @version 1.0 |
|
| 129 | - * @var array |
|
| 130 | - */ |
|
| 125 | + * List of allowed mime types |
|
| 126 | + * |
|
| 127 | + * @since 1.0 |
|
| 128 | + * @version 1.0 |
|
| 129 | + * @var array |
|
| 130 | + */ |
|
| 131 | 131 | private $allowed_mime_types = array(); |
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | - * Callbacks |
|
| 135 | - * |
|
| 136 | - * @since 1.0 |
|
| 137 | - * @version 1.0 |
|
| 138 | - * @var array |
|
| 139 | - */ |
|
| 134 | + * Callbacks |
|
| 135 | + * |
|
| 136 | + * @since 1.0 |
|
| 137 | + * @version 1.0 |
|
| 138 | + * @var array |
|
| 139 | + */ |
|
| 140 | 140 | private $callbacks = array('before' => null, 'after' => null); |
| 141 | 141 | |
| 142 | 142 | /** |
| 143 | - * File object |
|
| 144 | - * |
|
| 145 | - * @since 1.0 |
|
| 146 | - * @version 1.0 |
|
| 147 | - * @var object |
|
| 148 | - */ |
|
| 143 | + * File object |
|
| 144 | + * |
|
| 145 | + * @since 1.0 |
|
| 146 | + * @version 1.0 |
|
| 147 | + * @var object |
|
| 148 | + */ |
|
| 149 | 149 | private $file; |
| 150 | 150 | |
| 151 | 151 | /** |
| 152 | - * Helping mime types |
|
| 153 | - * |
|
| 154 | - * @since 1.0 |
|
| 155 | - * @version 1.0 |
|
| 156 | - * @var array |
|
| 157 | - */ |
|
| 152 | + * Helping mime types |
|
| 153 | + * |
|
| 154 | + * @since 1.0 |
|
| 155 | + * @version 1.0 |
|
| 156 | + * @var array |
|
| 157 | + */ |
|
| 158 | 158 | private $mime_helping = array( |
| 159 | 159 | 'text' => array('text/plain',), |
| 160 | 160 | 'image' => array( |
@@ -210,13 +210,13 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | |
| 212 | 212 | /** |
| 213 | - * Construct |
|
| 214 | - * |
|
| 215 | - * @since 0.1 |
|
| 216 | - * @version 1.0.1 |
|
| 217 | - * @return object |
|
| 218 | - * @method object __construct |
|
| 219 | - */ |
|
| 213 | + * Construct |
|
| 214 | + * |
|
| 215 | + * @since 0.1 |
|
| 216 | + * @version 1.0.1 |
|
| 217 | + * @return object |
|
| 218 | + * @method object __construct |
|
| 219 | + */ |
|
| 220 | 220 | public function __construct(){ |
| 221 | 221 | $this->logger =& class_loader('Log', 'classes'); |
| 222 | 222 | $this->logger->setLogger('Library::Upload'); |
@@ -260,17 +260,17 @@ discard block |
||
| 260 | 260 | $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array)); |
| 261 | 261 | } |
| 262 | 262 | /** |
| 263 | - * Set input. |
|
| 264 | - * If you have $_FILES["file"], you must use the key "file" |
|
| 265 | - * Example: |
|
| 266 | - * $object->setInput("file"); |
|
| 267 | - * |
|
| 268 | - * @since 1.0 |
|
| 269 | - * @version 1.0 |
|
| 270 | - * @param string $input |
|
| 271 | - * @return object |
|
| 272 | - * @method boolean setInput |
|
| 273 | - */ |
|
| 263 | + * Set input. |
|
| 264 | + * If you have $_FILES["file"], you must use the key "file" |
|
| 265 | + * Example: |
|
| 266 | + * $object->setInput("file"); |
|
| 267 | + * |
|
| 268 | + * @since 1.0 |
|
| 269 | + * @version 1.0 |
|
| 270 | + * @param string $input |
|
| 271 | + * @return object |
|
| 272 | + * @method boolean setInput |
|
| 273 | + */ |
|
| 274 | 274 | public function setInput($input) |
| 275 | 275 | { |
| 276 | 276 | if (!empty($input) && (is_string($input) || is_numeric($input) )) { |
@@ -279,18 +279,18 @@ discard block |
||
| 279 | 279 | return $this; |
| 280 | 280 | } |
| 281 | 281 | /** |
| 282 | - * Set new filename |
|
| 283 | - * Example: |
|
| 284 | - * FileUpload::setFilename("new file.txt") |
|
| 285 | - * Remember: |
|
| 286 | - * Use %s to retrive file extension |
|
| 287 | - * |
|
| 288 | - * @since 1.0 |
|
| 289 | - * @version 1.0 |
|
| 290 | - * @param string $filename |
|
| 291 | - * @return object |
|
| 292 | - * @method boolean setFilename |
|
| 293 | - */ |
|
| 282 | + * Set new filename |
|
| 283 | + * Example: |
|
| 284 | + * FileUpload::setFilename("new file.txt") |
|
| 285 | + * Remember: |
|
| 286 | + * Use %s to retrive file extension |
|
| 287 | + * |
|
| 288 | + * @since 1.0 |
|
| 289 | + * @version 1.0 |
|
| 290 | + * @param string $filename |
|
| 291 | + * @return object |
|
| 292 | + * @method boolean setFilename |
|
| 293 | + */ |
|
| 294 | 294 | public function setFilename($filename) |
| 295 | 295 | { |
| 296 | 296 | if ($this->isFilename($filename)) { |
@@ -299,14 +299,14 @@ discard block |
||
| 299 | 299 | return $this; |
| 300 | 300 | } |
| 301 | 301 | /** |
| 302 | - * Set automatic filename |
|
| 303 | - * |
|
| 304 | - * @since 1.0 |
|
| 305 | - * @version 1.5 |
|
| 306 | - * @param string $extension |
|
| 307 | - * @return object |
|
| 308 | - * @method boolean setAutoFilename |
|
| 309 | - */ |
|
| 302 | + * Set automatic filename |
|
| 303 | + * |
|
| 304 | + * @since 1.0 |
|
| 305 | + * @version 1.5 |
|
| 306 | + * @param string $extension |
|
| 307 | + * @return object |
|
| 308 | + * @method boolean setAutoFilename |
|
| 309 | + */ |
|
| 310 | 310 | public function setAutoFilename() |
| 311 | 311 | { |
| 312 | 312 | $this->filename = sha1(mt_rand(1, 9999).uniqid()); |
@@ -314,14 +314,14 @@ discard block |
||
| 314 | 314 | return $this; |
| 315 | 315 | } |
| 316 | 316 | /** |
| 317 | - * Set file size limit |
|
| 318 | - * |
|
| 319 | - * @since 1.0 |
|
| 320 | - * @version 1.0 |
|
| 321 | - * @param double $file_size |
|
| 322 | - * @return object |
|
| 323 | - * @method boolean setMaxFileSize |
|
| 324 | - */ |
|
| 317 | + * Set file size limit |
|
| 318 | + * |
|
| 319 | + * @since 1.0 |
|
| 320 | + * @version 1.0 |
|
| 321 | + * @param double $file_size |
|
| 322 | + * @return object |
|
| 323 | + * @method boolean setMaxFileSize |
|
| 324 | + */ |
|
| 325 | 325 | public function setMaxFileSize($file_size) |
| 326 | 326 | { |
| 327 | 327 | $file_size = $this->sizeInBytes($file_size); |
@@ -337,14 +337,14 @@ discard block |
||
| 337 | 337 | return $this; |
| 338 | 338 | } |
| 339 | 339 | /** |
| 340 | - * Set array mime types |
|
| 341 | - * |
|
| 342 | - * @since 1.0 |
|
| 343 | - * @version 1.0 |
|
| 344 | - * @param array $mimes |
|
| 345 | - * @return object |
|
| 346 | - * @method boolean setAllowedMimeTypes |
|
| 347 | - */ |
|
| 340 | + * Set array mime types |
|
| 341 | + * |
|
| 342 | + * @since 1.0 |
|
| 343 | + * @version 1.0 |
|
| 344 | + * @param array $mimes |
|
| 345 | + * @return object |
|
| 346 | + * @method boolean setAllowedMimeTypes |
|
| 347 | + */ |
|
| 348 | 348 | public function setAllowedMimeTypes(array $mimes) |
| 349 | 349 | { |
| 350 | 350 | if (count($mimes) > 0) { |
@@ -353,14 +353,14 @@ discard block |
||
| 353 | 353 | return $this; |
| 354 | 354 | } |
| 355 | 355 | /** |
| 356 | - * Set input callback |
|
| 357 | - * |
|
| 358 | - * @since 1.0 |
|
| 359 | - * @version 1.0 |
|
| 360 | - * @param mixed $callback |
|
| 361 | - * @return object |
|
| 362 | - * @method boolean setCallbackInput |
|
| 363 | - */ |
|
| 356 | + * Set input callback |
|
| 357 | + * |
|
| 358 | + * @since 1.0 |
|
| 359 | + * @version 1.0 |
|
| 360 | + * @param mixed $callback |
|
| 361 | + * @return object |
|
| 362 | + * @method boolean setCallbackInput |
|
| 363 | + */ |
|
| 364 | 364 | public function setCallbackInput($callback) |
| 365 | 365 | { |
| 366 | 366 | if (is_callable($callback, false)) { |
@@ -369,14 +369,14 @@ discard block |
||
| 369 | 369 | return $this; |
| 370 | 370 | } |
| 371 | 371 | /** |
| 372 | - * Set output callback |
|
| 373 | - * |
|
| 374 | - * @since 1.0 |
|
| 375 | - * @version 1.0 |
|
| 376 | - * @param mixed $callback |
|
| 377 | - * @return object |
|
| 378 | - * @method boolean setCallbackOutput |
|
| 379 | - */ |
|
| 372 | + * Set output callback |
|
| 373 | + * |
|
| 374 | + * @since 1.0 |
|
| 375 | + * @version 1.0 |
|
| 376 | + * @param mixed $callback |
|
| 377 | + * @return object |
|
| 378 | + * @method boolean setCallbackOutput |
|
| 379 | + */ |
|
| 380 | 380 | public function setCallbackOutput($callback) |
| 381 | 381 | { |
| 382 | 382 | if (is_callable($callback, false)) { |
@@ -385,14 +385,14 @@ discard block |
||
| 385 | 385 | return $this; |
| 386 | 386 | } |
| 387 | 387 | /** |
| 388 | - * Append a mime type to allowed mime types |
|
| 389 | - * |
|
| 390 | - * @since 1.0 |
|
| 391 | - * @version 1.0.1 |
|
| 392 | - * @param string $mime |
|
| 393 | - * @return object |
|
| 394 | - * @method boolean setAllowMimeType |
|
| 395 | - */ |
|
| 388 | + * Append a mime type to allowed mime types |
|
| 389 | + * |
|
| 390 | + * @since 1.0 |
|
| 391 | + * @version 1.0.1 |
|
| 392 | + * @param string $mime |
|
| 393 | + * @return object |
|
| 394 | + * @method boolean setAllowMimeType |
|
| 395 | + */ |
|
| 396 | 396 | public function setAllowMimeType($mime) |
| 397 | 397 | { |
| 398 | 398 | if (!empty($mime) && is_string($mime)) { |
@@ -402,13 +402,13 @@ discard block |
||
| 402 | 402 | return $this; |
| 403 | 403 | } |
| 404 | 404 | /** |
| 405 | - * Set allowed mime types from mime helping |
|
| 406 | - * |
|
| 407 | - * @since 1.0.1 |
|
| 408 | - * @version 1.0.1 |
|
| 409 | - * @return object |
|
| 410 | - * @method boolean setMimeHelping |
|
| 411 | - */ |
|
| 405 | + * Set allowed mime types from mime helping |
|
| 406 | + * |
|
| 407 | + * @since 1.0.1 |
|
| 408 | + * @version 1.0.1 |
|
| 409 | + * @return object |
|
| 410 | + * @method boolean setMimeHelping |
|
| 411 | + */ |
|
| 412 | 412 | public function setMimeHelping($name) |
| 413 | 413 | { |
| 414 | 414 | if (!empty($name) && is_string($name)) { |
@@ -419,17 +419,17 @@ discard block |
||
| 419 | 419 | return $this; |
| 420 | 420 | } |
| 421 | 421 | /** |
| 422 | - * Set function to upload file |
|
| 423 | - * Examples: |
|
| 424 | - * 1.- FileUpload::setUploadFunction("move_uploaded_file"); |
|
| 425 | - * 2.- FileUpload::setUploadFunction("copy"); |
|
| 426 | - * |
|
| 427 | - * @since 1.0 |
|
| 428 | - * @version 1.0 |
|
| 429 | - * @param string $function |
|
| 430 | - * @return object |
|
| 431 | - * @method boolean setUploadFunction |
|
| 432 | - */ |
|
| 422 | + * Set function to upload file |
|
| 423 | + * Examples: |
|
| 424 | + * 1.- FileUpload::setUploadFunction("move_uploaded_file"); |
|
| 425 | + * 2.- FileUpload::setUploadFunction("copy"); |
|
| 426 | + * |
|
| 427 | + * @since 1.0 |
|
| 428 | + * @version 1.0 |
|
| 429 | + * @param string $function |
|
| 430 | + * @return object |
|
| 431 | + * @method boolean setUploadFunction |
|
| 432 | + */ |
|
| 433 | 433 | public function setUploadFunction($function) |
| 434 | 434 | { |
| 435 | 435 | if (!empty($function) && (is_array($function) || is_string($function) )) { |
@@ -440,13 +440,13 @@ discard block |
||
| 440 | 440 | return $this; |
| 441 | 441 | } |
| 442 | 442 | /** |
| 443 | - * Clear allowed mime types cache |
|
| 444 | - * |
|
| 445 | - * @since 1.0 |
|
| 446 | - * @version 1.0 |
|
| 447 | - * @return object |
|
| 448 | - * @method boolean clearAllowedMimeTypes |
|
| 449 | - */ |
|
| 443 | + * Clear allowed mime types cache |
|
| 444 | + * |
|
| 445 | + * @since 1.0 |
|
| 446 | + * @version 1.0 |
|
| 447 | + * @return object |
|
| 448 | + * @method boolean clearAllowedMimeTypes |
|
| 449 | + */ |
|
| 450 | 450 | public function clearAllowedMimeTypes() |
| 451 | 451 | { |
| 452 | 452 | $this->allowed_mime_types = array(); |
@@ -454,15 +454,15 @@ discard block |
||
| 454 | 454 | return $this; |
| 455 | 455 | } |
| 456 | 456 | /** |
| 457 | - * Set destination output |
|
| 458 | - * |
|
| 459 | - * @since 1.0 |
|
| 460 | - * @version 1.0 |
|
| 461 | - * @param string $destination_directory Destination path |
|
| 462 | - * @param boolean $create_if_not_exist |
|
| 463 | - * @return object |
|
| 464 | - * @method boolean setDestinationDirectory |
|
| 465 | - */ |
|
| 457 | + * Set destination output |
|
| 458 | + * |
|
| 459 | + * @since 1.0 |
|
| 460 | + * @version 1.0 |
|
| 461 | + * @param string $destination_directory Destination path |
|
| 462 | + * @param boolean $create_if_not_exist |
|
| 463 | + * @return object |
|
| 464 | + * @method boolean setDestinationDirectory |
|
| 465 | + */ |
|
| 466 | 466 | public function setDestinationDirectory($destination_directory, $create_if_not_exist = false) { |
| 467 | 467 | $destination_directory = realpath($destination_directory); |
| 468 | 468 | if (substr($destination_directory, -1) != DIRECTORY_SEPARATOR) { |
@@ -486,14 +486,14 @@ discard block |
||
| 486 | 486 | return $this; |
| 487 | 487 | } |
| 488 | 488 | /** |
| 489 | - * Check file exists |
|
| 490 | - * |
|
| 491 | - * @since 1.0 |
|
| 492 | - * @version 1.0.1 |
|
| 493 | - * @param string $file_destination |
|
| 494 | - * @return boolean |
|
| 495 | - * @method boolean fileExists |
|
| 496 | - */ |
|
| 489 | + * Check file exists |
|
| 490 | + * |
|
| 491 | + * @since 1.0 |
|
| 492 | + * @version 1.0.1 |
|
| 493 | + * @param string $file_destination |
|
| 494 | + * @return boolean |
|
| 495 | + * @method boolean fileExists |
|
| 496 | + */ |
|
| 497 | 497 | public function fileExists($file_destination) |
| 498 | 498 | { |
| 499 | 499 | if ($this->isFilename($file_destination)) { |
@@ -502,14 +502,14 @@ discard block |
||
| 502 | 502 | return false; |
| 503 | 503 | } |
| 504 | 504 | /** |
| 505 | - * Check dir exists |
|
| 506 | - * |
|
| 507 | - * @since 1.0 |
|
| 508 | - * @version 1.0.1 |
|
| 509 | - * @param string $path |
|
| 510 | - * @return boolean |
|
| 511 | - * @method boolean dirExists |
|
| 512 | - */ |
|
| 505 | + * Check dir exists |
|
| 506 | + * |
|
| 507 | + * @since 1.0 |
|
| 508 | + * @version 1.0.1 |
|
| 509 | + * @param string $path |
|
| 510 | + * @return boolean |
|
| 511 | + * @method boolean dirExists |
|
| 512 | + */ |
|
| 513 | 513 | public function dirExists($path) |
| 514 | 514 | { |
| 515 | 515 | if ($this->isDirpath($path)) { |
@@ -518,29 +518,29 @@ discard block |
||
| 518 | 518 | return false; |
| 519 | 519 | } |
| 520 | 520 | /** |
| 521 | - * Check valid filename |
|
| 522 | - * |
|
| 523 | - * @since 1.0 |
|
| 524 | - * @version 1.0.1 |
|
| 525 | - * @param string $filename |
|
| 526 | - * @return boolean |
|
| 527 | - * @method boolean isFilename |
|
| 528 | - */ |
|
| 521 | + * Check valid filename |
|
| 522 | + * |
|
| 523 | + * @since 1.0 |
|
| 524 | + * @version 1.0.1 |
|
| 525 | + * @param string $filename |
|
| 526 | + * @return boolean |
|
| 527 | + * @method boolean isFilename |
|
| 528 | + */ |
|
| 529 | 529 | public function isFilename($filename) |
| 530 | 530 | { |
| 531 | 531 | $filename = basename($filename); |
| 532 | 532 | return (!empty($filename) && (is_string( $filename) || is_numeric($filename))); |
| 533 | 533 | } |
| 534 | 534 | /** |
| 535 | - * Validate mime type with allowed mime types, |
|
| 536 | - * but if allowed mime types is empty, this method return true |
|
| 537 | - * |
|
| 538 | - * @since 1.0 |
|
| 539 | - * @version 1.0 |
|
| 540 | - * @param string $mime |
|
| 541 | - * @return boolean |
|
| 542 | - * @method boolean checkMimeType |
|
| 543 | - */ |
|
| 535 | + * Validate mime type with allowed mime types, |
|
| 536 | + * but if allowed mime types is empty, this method return true |
|
| 537 | + * |
|
| 538 | + * @since 1.0 |
|
| 539 | + * @version 1.0 |
|
| 540 | + * @param string $mime |
|
| 541 | + * @return boolean |
|
| 542 | + * @method boolean checkMimeType |
|
| 543 | + */ |
|
| 544 | 544 | public function checkMimeType($mime) |
| 545 | 545 | { |
| 546 | 546 | if (count($this->allowed_mime_types) == 0) { |
@@ -549,26 +549,26 @@ discard block |
||
| 549 | 549 | return in_array(strtolower($mime), $this->allowed_mime_types); |
| 550 | 550 | } |
| 551 | 551 | /** |
| 552 | - * Retrive status of upload |
|
| 553 | - * |
|
| 554 | - * @since 1.0 |
|
| 555 | - * @version 1.0 |
|
| 556 | - * @return boolean |
|
| 557 | - * @method boolean getStatus |
|
| 558 | - */ |
|
| 552 | + * Retrive status of upload |
|
| 553 | + * |
|
| 554 | + * @since 1.0 |
|
| 555 | + * @version 1.0 |
|
| 556 | + * @return boolean |
|
| 557 | + * @method boolean getStatus |
|
| 558 | + */ |
|
| 559 | 559 | public function getStatus() |
| 560 | 560 | { |
| 561 | 561 | return $this->file['status']; |
| 562 | 562 | } |
| 563 | 563 | /** |
| 564 | - * Check valid path |
|
| 565 | - * |
|
| 566 | - * @since 1.0 |
|
| 567 | - * @version 1.0.1 |
|
| 568 | - * @param string $filename |
|
| 569 | - * @return boolean |
|
| 570 | - * @method boolean isDirpath |
|
| 571 | - */ |
|
| 564 | + * Check valid path |
|
| 565 | + * |
|
| 566 | + * @since 1.0 |
|
| 567 | + * @version 1.0.1 |
|
| 568 | + * @param string $filename |
|
| 569 | + * @return boolean |
|
| 570 | + * @method boolean isDirpath |
|
| 571 | + */ |
|
| 572 | 572 | public function isDirpath($path) |
| 573 | 573 | { |
| 574 | 574 | if (!empty( $path) && (is_string( $path) || is_numeric($path) )) { |
@@ -581,26 +581,26 @@ discard block |
||
| 581 | 581 | return false; |
| 582 | 582 | } |
| 583 | 583 | /** |
| 584 | - * Allow overwriting files |
|
| 585 | - * |
|
| 586 | - * @since 1.0 |
|
| 587 | - * @version 1.0 |
|
| 588 | - * @return object |
|
| 589 | - * @method boolean allowOverwriting |
|
| 590 | - */ |
|
| 584 | + * Allow overwriting files |
|
| 585 | + * |
|
| 586 | + * @since 1.0 |
|
| 587 | + * @version 1.0 |
|
| 588 | + * @return object |
|
| 589 | + * @method boolean allowOverwriting |
|
| 590 | + */ |
|
| 591 | 591 | public function allowOverwriting() |
| 592 | 592 | { |
| 593 | 593 | $this->overwrite_file = true; |
| 594 | 594 | return $this; |
| 595 | 595 | } |
| 596 | 596 | /** |
| 597 | - * File info |
|
| 598 | - * |
|
| 599 | - * @since 1.0 |
|
| 600 | - * @version 1.0 |
|
| 601 | - * @return object |
|
| 602 | - * @method object getInfo |
|
| 603 | - */ |
|
| 597 | + * File info |
|
| 598 | + * |
|
| 599 | + * @since 1.0 |
|
| 600 | + * @version 1.0 |
|
| 601 | + * @return object |
|
| 602 | + * @method object getInfo |
|
| 603 | + */ |
|
| 604 | 604 | public function getInfo() |
| 605 | 605 | { |
| 606 | 606 | return (object)$this->file; |
@@ -618,13 +618,13 @@ discard block |
||
| 618 | 618 | |
| 619 | 619 | |
| 620 | 620 | /** |
| 621 | - * Upload file |
|
| 622 | - * |
|
| 623 | - * @since 1.0 |
|
| 624 | - * @version 1.0.1 |
|
| 625 | - * @return boolean |
|
| 626 | - * @method boolean save |
|
| 627 | - */ |
|
| 621 | + * Upload file |
|
| 622 | + * |
|
| 623 | + * @since 1.0 |
|
| 624 | + * @version 1.0.1 |
|
| 625 | + * @return boolean |
|
| 626 | + * @method boolean save |
|
| 627 | + */ |
|
| 628 | 628 | public function save(){ |
| 629 | 629 | if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) { |
| 630 | 630 | // set original filename if not have a new name |
@@ -681,15 +681,15 @@ discard block |
||
| 681 | 681 | |
| 682 | 682 | |
| 683 | 683 | /** |
| 684 | - * File size for humans. |
|
| 685 | - * |
|
| 686 | - * @since 1.0 |
|
| 687 | - * @version 1.0 |
|
| 688 | - * @param integer $bytes |
|
| 689 | - * @param integer $precision |
|
| 690 | - * @return string |
|
| 691 | - * @method string sizeFormat |
|
| 692 | - */ |
|
| 684 | + * File size for humans. |
|
| 685 | + * |
|
| 686 | + * @since 1.0 |
|
| 687 | + * @version 1.0 |
|
| 688 | + * @param integer $bytes |
|
| 689 | + * @param integer $precision |
|
| 690 | + * @return string |
|
| 691 | + * @method string sizeFormat |
|
| 692 | + */ |
|
| 693 | 693 | public function sizeFormat($size, $precision = 2) |
| 694 | 694 | { |
| 695 | 695 | if($size > 0){ |
@@ -702,14 +702,14 @@ discard block |
||
| 702 | 702 | |
| 703 | 703 | |
| 704 | 704 | /** |
| 705 | - * Convert human file size to bytes |
|
| 706 | - * |
|
| 707 | - * @since 1.0 |
|
| 708 | - * @version 1.0.1 |
|
| 709 | - * @param integer|double $size |
|
| 710 | - * @return integer|double |
|
| 711 | - * @method string sizeInBytes |
|
| 712 | - */ |
|
| 705 | + * Convert human file size to bytes |
|
| 706 | + * |
|
| 707 | + * @since 1.0 |
|
| 708 | + * @version 1.0.1 |
|
| 709 | + * @param integer|double $size |
|
| 710 | + * @return integer|double |
|
| 711 | + * @method string sizeInBytes |
|
| 712 | + */ |
|
| 713 | 713 | public function sizeInBytes($size) |
| 714 | 714 | { |
| 715 | 715 | $unit = 'B'; |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | return true; |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | - //check for php upload error |
|
| 764 | + //check for php upload error |
|
| 765 | 765 | if(is_numeric($this->file['error']) && $this->file['error'] > 0){ |
| 766 | 766 | $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error'])); |
| 767 | 767 | return true; |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | return true; |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | - // Check file size |
|
| 776 | + // Check file size |
|
| 777 | 777 | if ($this->max_file_size > 0 && $this->max_file_size < $this->file['size']) { |
| 778 | 778 | $this->setError(sprintf($this->error_messages['max_file_size'], $this->sizeFormat($this->max_file_size))); |
| 779 | 779 | return true; |
@@ -1,25 +1,25 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | 3 | |
| 4 | - /** |
|
| 5 | - * |
|
| 6 | - */ |
|
| 7 | - class Home extends Controller { |
|
| 4 | + /** |
|
| 5 | + * |
|
| 6 | + */ |
|
| 7 | + class Home extends Controller { |
|
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * the class constructor |
|
| 11 | - */ |
|
| 12 | - public function __construct() { |
|
| 13 | - parent::__construct(); |
|
| 14 | - } |
|
| 9 | + /** |
|
| 10 | + * the class constructor |
|
| 11 | + */ |
|
| 12 | + public function __construct() { |
|
| 13 | + parent::__construct(); |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * The default method |
|
| 18 | - * @return null |
|
| 19 | - */ |
|
| 20 | - public function index() { |
|
| 21 | - Loader::library('Assets'); |
|
| 22 | - Loader::library('Html'); |
|
| 23 | - $this->response->render('home'); |
|
| 24 | - } |
|
| 25 | - } |
|
| 16 | + /** |
|
| 17 | + * The default method |
|
| 18 | + * @return null |
|
| 19 | + */ |
|
| 20 | + public function index() { |
|
| 21 | + Loader::library('Assets'); |
|
| 22 | + Loader::library('Html'); |
|
| 23 | + $this->response->render('home'); |
|
| 24 | + } |
|
| 25 | + } |
|
@@ -1,31 +1,31 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class RequestTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class RequestTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public static function tearDownAfterClass() |
|
| 14 | - { |
|
| 13 | + public static function tearDownAfterClass() |
|
| 14 | + { |
|
| 15 | 15 | |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function testNotYet() |
|
| 27 | - { |
|
| 28 | - $this->markTestSkipped(); |
|
| 29 | - } |
|
| 26 | + public function testNotYet() |
|
| 27 | + { |
|
| 28 | + $this->markTestSkipped(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - } |
|
| 32 | 31 | \ No newline at end of file |
| 32 | + } |
|
| 33 | 33 | \ No newline at end of file |
@@ -1,31 +1,31 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class LoaderTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class LoaderTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public static function tearDownAfterClass() |
|
| 14 | - { |
|
| 13 | + public static function tearDownAfterClass() |
|
| 14 | + { |
|
| 15 | 15 | |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function testNotYet() |
|
| 27 | - { |
|
| 28 | - $this->markTestSkipped(); |
|
| 29 | - } |
|
| 26 | + public function testNotYet() |
|
| 27 | + { |
|
| 28 | + $this->markTestSkipped(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - } |
|
| 32 | 31 | \ No newline at end of file |
| 32 | + } |
|
| 33 | 33 | \ No newline at end of file |
@@ -1,33 +1,33 @@ |
||
| 1 | 1 | <?php |
| 2 | - use PHPUnit\Framework\TestCase; |
|
| 2 | + use PHPUnit\Framework\TestCase; |
|
| 3 | 3 | |
| 4 | - class SessionTest extends TestCase |
|
| 5 | - { |
|
| 4 | + class SessionTest extends TestCase |
|
| 5 | + { |
|
| 6 | 6 | |
| 7 | - public static function setUpBeforeClass() |
|
| 8 | - { |
|
| 7 | + public static function setUpBeforeClass() |
|
| 8 | + { |
|
| 9 | 9 | |
| 10 | - } |
|
| 10 | + } |
|
| 11 | 11 | |
| 12 | - public static function tearDownAfterClass() |
|
| 13 | - { |
|
| 12 | + public static function tearDownAfterClass() |
|
| 13 | + { |
|
| 14 | 14 | |
| 15 | - } |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - // tests |
|
| 27 | - public function testSomeFeature() |
|
| 28 | - { |
|
| 29 | - Session::set('foo', 'bar'); |
|
| 30 | - $this->assertEquals('bar', Session::get('foo')); |
|
| 31 | - //$this->expectException(InvalidArgumentException::class); |
|
| 32 | - } |
|
| 33 | - } |
|
| 34 | 26 | \ No newline at end of file |
| 27 | + // tests |
|
| 28 | + public function testSomeFeature() |
|
| 29 | + { |
|
| 30 | + Session::set('foo', 'bar'); |
|
| 31 | + $this->assertEquals('bar', Session::get('foo')); |
|
| 32 | + //$this->expectException(InvalidArgumentException::class); |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | 35 | \ No newline at end of file |
@@ -1,31 +1,31 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class UrlTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class UrlTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public static function tearDownAfterClass() |
|
| 14 | - { |
|
| 13 | + public static function tearDownAfterClass() |
|
| 14 | + { |
|
| 15 | 15 | |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function testNotYet() |
|
| 27 | - { |
|
| 28 | - $this->markTestSkipped(); |
|
| 29 | - } |
|
| 26 | + public function testNotYet() |
|
| 27 | + { |
|
| 28 | + $this->markTestSkipped(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - } |
|
| 32 | 31 | \ No newline at end of file |
| 32 | + } |
|
| 33 | 33 | \ No newline at end of file |
@@ -1,31 +1,31 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class LogTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class LogTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public static function tearDownAfterClass() |
|
| 14 | - { |
|
| 13 | + public static function tearDownAfterClass() |
|
| 14 | + { |
|
| 15 | 15 | |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function testNotYet() |
|
| 27 | - { |
|
| 28 | - $this->markTestSkipped(); |
|
| 29 | - } |
|
| 26 | + public function testNotYet() |
|
| 27 | + { |
|
| 28 | + $this->markTestSkipped(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - } |
|
| 32 | 31 | \ No newline at end of file |
| 32 | + } |
|
| 33 | 33 | \ No newline at end of file |
@@ -1,31 +1,31 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class ModelTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class ModelTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public static function tearDownAfterClass() |
|
| 14 | - { |
|
| 13 | + public static function tearDownAfterClass() |
|
| 14 | + { |
|
| 15 | 15 | |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function testNotYet() |
|
| 27 | - { |
|
| 28 | - $this->markTestSkipped(); |
|
| 29 | - } |
|
| 26 | + public function testNotYet() |
|
| 27 | + { |
|
| 28 | + $this->markTestSkipped(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - } |
|
| 32 | 31 | \ No newline at end of file |
| 32 | + } |
|
| 33 | 33 | \ No newline at end of file |
@@ -1,31 +1,31 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class DBSessionHandlerModelTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class DBSessionHandlerModelTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public static function tearDownAfterClass() |
|
| 14 | - { |
|
| 13 | + public static function tearDownAfterClass() |
|
| 14 | + { |
|
| 15 | 15 | |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function testNotYet() |
|
| 27 | - { |
|
| 28 | - $this->markTestSkipped(); |
|
| 29 | - } |
|
| 26 | + public function testNotYet() |
|
| 27 | + { |
|
| 28 | + $this->markTestSkipped(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - } |
|
| 32 | 31 | \ No newline at end of file |
| 32 | + } |
|
| 33 | 33 | \ No newline at end of file |