code/FileVersion.php
protected function saveCurrentVersion()
    {
        // Ensure we re-fetch fresh record from database (in case it was recently renamed / moved)
        $file = File::get()->byID($this->FileID);
        if ($file->ParentID) {
            $base = Controller::join_links(
                $file->Parent()->getFullPath(),
                self::VERSION_FOLDER,
                $this->FileID
            );
        } else {
            $base = Controller::join_links(
                Director::baseFolder(),
                ASSETS_DIR,
                self::VERSION_FOLDER,
                $this->FileID
            );
        }

        Filesystem::makeFolder($base);

        $extension = $file->getExtension();
        $basename  = basename($file->Name, $extension);
        $version   = $this->VersionNumber;

        $cachedPath = Controller::join_links(
            $base, "{$basename}$version.$extension"
        );

        if (!copy($file->getFullPath(), $cachedPath)) {
            throw new Exception(
                "Unable to copy version #$version of file #$this->FileID from:\n \"{$file->getFullPath()}\"\nto:\n\"$cachedPath\""
            );
        }

        return Director::makeRelative($cachedPath);
    }
protected function saveCurrentVersion()
    {
        // Ensure we re-fetch fresh record from database (in case it was recently renamed / moved)
        $file = File::get()->byID($this->FileID);
        if ($file->ParentID) {
            $base = Controller::join_links(
                $file->Parent()->getFullPath(),
                self::VERSION_FOLDER,
                $this->FileID
            );
        } else {
            $base = Controller::join_links(
                Director::baseFolder(),
                ASSETS_DIR,
                self::VERSION_FOLDER,
                $this->FileID
            );
        }

        Filesystem::makeFolder($base);

        $extension = $file->getExtension();
        $basename  = basename($file->Name, $extension);
        $version   = $this->VersionNumber;

        $cachedPath = Controller::join_links(
            $base, "{$basename}$version.$extension"
        );

        if (!copy($file->getFullPath(), $cachedPath)) {
            throw new Exception(
                "Unable to copy version #$version of file #$this->FileID from:\n \"{$file->getFullPath()}\"\nto:\n\"$cachedPath\""
            );
        }

        return Director::makeRelative($cachedPath);
    }
protected function saveCurrentVersion ( ) { // Ensure we re-fetch fresh record from database (in case it was recently renamed / moved) $ file = File :: get ( ) -> byID ( $ this -> FileID ) ; if ( $ file -> ParentID ) { $ base = Controller :: join_links ( $ file -> Parent ( ) -> getFullPath ( ) , self :: VERSION_FOLDER , $ this -> FileID ) ; } else { $ base = Controller :: join_links ( Director :: baseFolder ( ) , ASSETS_DIR , self :: VERSION_FOLDER , $ this -> FileID ) ; } Filesystem :: makeFolder ( $ base ) ; $ extension = $ file -> getExtension ( ) ; $ basename = basename ( $ file -> Name , $ extension ) ; $ version = $ this -> VersionNumber ; $ cachedPath = Controller :: join_links ( $ base , "{$basename}$version.$extension" ) ; if ( ! copy ( $ file -> getFullPath ( ) , $ cachedPath ) ) { throw new Exception ( "Unable to copy version #$version of file #$this->FileID from:\n \"{$file->getFullPath()}\"\nto:\n\"$cachedPath\"" ) ; } return Director :: makeRelative ( $ cachedPath ) ; }
Saves the current version of the linked File object in a versions
directory, then returns the relative path to where it is stored.

@return string
Saves the current version of the linked File object in a versions directory then returns the relative path to where it is stored .