public function setUploadDir($dir)
    {
        // Check to see if the upload directory exists.
        if (!file_exists($dir) || !is_dir($dir)) {
            $this->error = self::UPLOAD_ERR_DIR_NOT_EXIST;
        // Check to see if the permissions are set correctly.
        } else if (!is_writable($dir)) {
            $this->error = self::UPLOAD_ERR_DIR_NOT_WRITABLE;
        }

        $this->uploadDir = $dir;
        return $this;
    }