Changeset 2645

Show
Ignore:
Timestamp:
05/06/08 15:19:02 (3 months ago)
Author:
Shadowhand
Message:

Changes to upload helper:

  • Added upload::required()
  • Modified upload::valid()
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/system/helpers/upload.php

    r2469 r2645  
    4040                        $directory = Config::item('upload.directory', TRUE); 
    4141                } 
    42                 else 
    43                 { 
    44                         // Make sure the directory ends with a slash 
    45                         $directory = rtrim($directory, '/').'/'; 
    46                 } 
     42 
     43                // Make sure the directory ends with a slash 
     44                $directory = rtrim($directory, '/').'/'; 
    4745 
    4846                if ( ! is_writable($directory)) 
     
    6159 
    6260        /** 
    63          * Tests if a $_FILES item is valid
     61         * Tests if a $_FILES item exists
    6462         * 
    65          * @param   array    $_FILES item 
    66          * @return  boolean 
     63         * @param   array  $_FILES item 
     64         * @return  bool 
    6765         */ 
    68         public static function valid($file
     66        public static function required(
    6967        { 
    7068                return (is_array($file) 
     
    7371                        AND isset($file['type']) 
    7472                        AND isset($file['tmp_name']) 
    75                         AND isset($file['size']) 
     73                        AND isset($file['size'])); 
     74        } 
     75 
     76        /** 
     77         * Tests if a $_FILES item is valid. 
     78         * 
     79         * @param   array    $_FILES item 
     80         * @return  bool 
     81         */ 
     82        public static function valid($file) 
     83        { 
     84                return (isset($file['tmp_name']) 
     85                        AND isset($file['error']) 
    7686                        AND is_uploaded_file($file['tmp_name']) 
    7787                        AND $file['error'] === UPLOAD_ERR_OK); 
     
    8393         * @param   array    $_FILES item 
    8494         * @param   array    allowed file extensions 
    85          * @return  boolean 
     95         * @return  bool 
    8696         */ 
    8797        public static function type(array $file, array $allowed_types) 
    8898        { 
    8999                // Get the default extension of the file 
    90                 $extension = strtolower(preg_replace('/^.+\.(.+?)$/', '$1', $file['name'])); 
     100                $extension = strtolower(file::extension($file['name'])); 
    91101 
    92102                // Get the mime types for the extension 
     
    105115         * @param   array    $_FILES item 
    106116         * @param   array    maximum file size 
    107          * @return  boolean 
     117         * @return  bool 
    108118         */ 
    109119        public function size(array $file, array $size)