public function store($folder, $filename = null)
    {
        // check for errors
        if ($this->getError() == UPLOAD_ERR_OK) {
            throw new FilesException('Unable to move the file because an upload error occurred.');
        }

        // validate filename
        $filename = isset($filename) ? $filename : $this->getName();

        // validate folder
        $folder = $this->str($folder);
        if (!$folder->endsWith('/') && !$folder->endsWith('\\')) {
            $folder = $folder->val() . DIRECTORY_SEPARATOR;
        } else {
            $folder->val();
        }

        // check if we have already stored the file
        $path = $folder . $filename;
        if ($this->stored && $this->storedPath == $path) {
            return true;
        }

        // move the file
        try {
            $result = move_uploaded_file($this->tmpName, $path);
            if (!$result) {
                throw new FilesException('Unable to store file.');
            }
            $this->stored = $result;
            $this->storedPath = $folder . $filename;
        } catch (\Exception $e) {
            throw new FilesException($e->getMessage());
        }

        return $result;
    }