public function getFilePath(FileManager $file_manager)
    {
        $current_file = $file_manager->getCurrentFile();
        $target_file = $file_manager->getTargetFile();

        if (($current_file->getFilename() == "" && !is_null($target_file->getFilename()))) {
            throw new \Exception("Filename cannot be empty when there is a target file");
        }

        $root = $file_manager->getUploadPath();
        $dir_path = $file_manager->getDirPath();

        if (empty($dir_path)) {
            $dir = $root;
        } else {
            if (strcasecmp("../", $dir_path) >= 1) {
                throw new \Exception("Invalid filepath or filename");
            }
            $dir = $this->getFileManager()->DirTrim($root, $dir_path, true);
        }

        try {
            $file_manager->checkPath($dir);
            if (!is_null($target_file)) {
                $file_manager->checkPath($target_file->getFilepath(true));
            }
        } catch (\Exception $e) {
            throw new \Exception($e->getMessage(), $e->getCode());
        }

        return $dir;
    }