public function upload($overwrite = false) {
        $data = $this->_data;

        if (empty($data['tmp_name'])) {
            throw new ValidationException('Invalid file detected for upload');
        }

        // Check upload errors
        if ($data['error'] > 0 || !$this->_isUploadedFile($data['tmp_name'])) {
            switch ($data['error']) {
                case UPLOAD_ERR_INI_SIZE:
                case UPLOAD_ERR_FORM_SIZE:
                    $error = 'File exceeds the maximum file size';
                break;
                case UPLOAD_ERR_PARTIAL:
                    $error = 'File was only partially uploaded';
                break;
                case UPLOAD_ERR_NO_FILE:
                    $error = 'No file was found for upload';
                break;
                default:
                    $error = 'File failed to upload';
                break;
            }

            throw new ValidationException($error);
        }

        // Validate rules
        if ($validator = $this->getValidator()) {
            $validator
                ->setFile(new File($data))
                ->validate();
        }

        // Upload the file
        $target = $this->findDestination($data['name'], $overwrite);

        if ($this->_moveUploadedFile($data['tmp_name'], $target)) {
            $data['name'] = basename($target);
            $data['tmp_name'] = $target;

            $this->_file = new File($data);

            return true;
        }

        throw new ValidationException('An unknown error has occurred');
    }
public function upload($overwrite = false) {
        $data = $this->_data;

        if (empty($data['tmp_name'])) {
            throw new ValidationException('Invalid file detected for upload');
        }

        // Check upload errors
        if ($data['error'] > 0 || !$this->_isUploadedFile($data['tmp_name'])) {
            switch ($data['error']) {
                case UPLOAD_ERR_INI_SIZE:
                case UPLOAD_ERR_FORM_SIZE:
                    $error = 'File exceeds the maximum file size';
                break;
                case UPLOAD_ERR_PARTIAL:
                    $error = 'File was only partially uploaded';
                break;
                case UPLOAD_ERR_NO_FILE:
                    $error = 'No file was found for upload';
                break;
                default:
                    $error = 'File failed to upload';
                break;
            }

            throw new ValidationException($error);
        }

        // Validate rules
        if ($validator = $this->getValidator()) {
            $validator
                ->setFile(new File($data))
                ->validate();
        }

        // Upload the file
        $target = $this->findDestination($data['name'], $overwrite);

        if ($this->_moveUploadedFile($data['tmp_name'], $target)) {
            $data['name'] = basename($target);
            $data['tmp_name'] = $target;

            $this->_file = new File($data);

            return true;
        }

        throw new ValidationException('An unknown error has occurred');
    }
public function upload ( $ overwrite = false ) { $ data = $ this -> _data ; if ( empty ( $ data [ 'tmp_name' ] ) ) { throw new ValidationException ( 'Invalid file detected for upload' ) ; } // Check upload errors if ( $ data [ 'error' ] > 0 || ! $ this -> _isUploadedFile ( $ data [ 'tmp_name' ] ) ) { switch ( $ data [ 'error' ] ) { case UPLOAD_ERR_INI_SIZE : case UPLOAD_ERR_FORM_SIZE : $ error = 'File exceeds the maximum file size' ; break ; case UPLOAD_ERR_PARTIAL : $ error = 'File was only partially uploaded' ; break ; case UPLOAD_ERR_NO_FILE : $ error = 'No file was found for upload' ; break ; default : $ error = 'File failed to upload' ; break ; } throw new ValidationException ( $ error ) ; } // Validate rules if ( $ validator = $ this -> getValidator ( ) ) { $ validator -> setFile ( new File ( $ data ) ) -> validate ( ) ; } // Upload the file $ target = $ this -> findDestination ( $ data [ 'name' ] , $ overwrite ) ; if ( $ this -> _moveUploadedFile ( $ data [ 'tmp_name' ] , $ target ) ) { $ data [ 'name' ] = basename ( $ target ) ; $ data [ 'tmp_name' ] = $ target ; $ this -> _file = new File ( $ data ) ; return true ; } throw new ValidationException ( 'An unknown error has occurred' ) ; }
Upload the file to the target directory.

@param bool $overwrite
@return bool
@throws \Transit\Exception\ValidationException
Upload the file to the target directory .