Nate Lewis


FWS::V2::File - Framework Sites version 2 text and image file methods


Version 1.13091122


    use FWS::V2;

    my $fws = FWS::V2->new();

    # retrieve a reference to an array of data we asked for
    my $fileArrayRef = $fws->fileArray( directory   => "/home/directory" );


Framework Sites version 2 file writing, reading and manipulation methods.



Create a backup of the filesSecurePath, filesPath and the database and place it under the filesSecurePath backups directory. The file names will be date keyed and be processed by the restoreFWS method by they keyed date string. This will exclude any table that has the word 'session' in it, or anything that starts with 'admin_'.

Parameters: id: file name of files - the date string in numbers will be used if no id is passed excludeTables: Comma delimited list of tables you do not want to back up excludeFiles: Do not backup the FWS web accessable files minMode: Only backup anything that HAS to be there, no core, no js and css backup files. excludeSiteFiles: Backup site files related to plugins and the fws instance, but not the once related to the site excludeSecureFiles: Do not backup the secure files

Usage: $fws->backupFWS(%params);

Inside of the if you add certain site wide paramaters it will alter the behaviour of the backup"

    $fws->{FWSBackupExcludeTables} = 'notThisSiteTableThatsSpecial,orThisOne';


Restore a backup created by backupFWS. This will overwrite the files in place that are the same, and will replace all database tables with the one from the restore that are restored. All tables, and files not part of the restore will be left untouched.

    $fws->restoreFWS( id => 'someID' );


Create all of the derived images from a file upload based on its schema definition

    my %dataHashToUpdate = $fws->dataHash(guid=>'someGUIDThatHasImagesToUpdate');

If the data hash might not be correct because it is actually stored in a different table you can pass the field name you wish to update



Return a directory listing into a FWS hash array reference.

    # retrieve a reference to an array of data we asked for
    my $fileArray = $fws->fileArray( directory   =>'/home/directory' );

    # loop though the array printing the files we found
    for my $i (0 .. $#$fileArray) {
        print $fileArray->[$i]{file}. "\n";


Return a reference to a hash array from its human readable formMap. The format is new line delmited per array item then subsectioned by |, then name valued paired with ~ per each subsection. The first item of each | and ~ delemited section is translaged into the name hash key while the rest of the ~ delemented are convered into a name value pair.


    title 1~type~type 1|sub title 1a|sub title 1b
    title 2~something~extra|sub title 2a~extaKey~extra value|sub title 2b

Will return:

        'name' => 'title 1',
        'type' => 'type 1',
        'optionArray' => [
                   { 'name' => 'sub title 1a' },
                   { 'name' => 'sub title 1b' }
        'name' => 'title 2',
        'something' => 'extra',
        'optionArray' => [
                   { 'name' => 'sub title 2a', 'extaKey' => 'extra value' },
                   { 'name' => 'sub title 2b' }


Retrive a file and convert it into a base 64 encoded binary.

    # Get the file
    my $base64String = $fws->getEncodedBinary( $someFileWeWantToConvert );


The counterpart to packDirectory. This will put the files under the directory you choose from a file created by packDirectory.

    # Put the files somewhere
    $fws->unpackDirectory( directory => $someDirectory, fileName => '/something' );

uploadFile {

Run generic upload file routine.

    $fws->uploadFile( '/directory', $FILEHANDLE, 'newfilename.ext' );


MIME encode a directory ready for a FWS export. This will exclude anything that starts with /backup, /cache, /import_ or ends with .log or .pm.someDateNumber.

    # Get the file
    my $packedFileString = $fws->packDirectory( directory => $someDirectory );

You can also pass the key directoryList, and it will only add directories on this comma delimtied list unless the file begins with FWS.

    # Only grab fws and plugins dirs
    my $packedFileString = $fws->packDirectory( directory => $someDirectory, directoryList => '/fws,/plugins' );


Decode a base 64 encoded string and save it as its file.

    # Save the file
    $fws->saveEncodedBinary( $someFileWeWantToSave, $theBase64EcodedString );


Extract the version and description from a FWS plugin. If no version is labeled or exists it will return 0.0000 and the description will be blank.

    # get the info from the plugin
    my %pluginInfo = $fws->pluginInfo( $somePluginFile );
    print "Description: " . $pluginInfo{description} . "\n";
    print "Version: " . $pluginInfo{version} . "\n";
    print "Author: " . $pluginInfo{author} . "\n";
    print "Author Email: " . $pluginInfo{authorEmail} . "\n";


Make a new directory with built in safety mechanics. If the directory is not under the filePath or fileSecurePath then nothing will be created.

    $fws->makeDir( directory => $self->{filePath} . '/thisNewDir' );

This by default is ran in safe mode, making sure directorys are only created in the filePath or fileSecurePath. This can be turned off by passing nonFWS => 1.


Run init scripts for a site. This can only be used after setSiteValues() or setSiteFiendly() is called.



Run a FWS element script. This should not be used outside of the FWS core. There is no recursion or security checking and should not be used inside of elements to perfent possible recursion. Only use this if you are absolutly sure of the script content and its safety.

    %valueHash = $fws->runScript( 'scriptName', %valueHash );


Save an image with a unique width or height. The file will be converted to extensions graphic type of the fileName passed. Source, fileName and either width or height is required.

    # convert this png, to a jpg that is 110x110
        sourceFile  => '/somefile.png',
        fileName    => '/theNewFile.jpg',
        width       => '110',
        height      => '110'

    # convert this png, to a jpg that is 110x110 but chop off the bottom of the height if it resizes to larget then 110 instead of shrinking or stretching
        sourceFile  =>'/somefile.png',
        fileName    =>'/theNewFile.jpg',
        width       =>'110',
        cropHeight  =>'110'


Decrypt data if a site has the proper configuration

    my $decryptedData = $fws->FWSDecrypt( 'alsdkjfalkj230948lkjxldkfj' );


Encrypt data if a site has the proper configuration

    my $encryptedData = $fws->FWSEncrypt( 'encrypt this stuff' );


Read x number of lines from the end of a file. If lines are not specified it will default to 10.

    # Print last 10 lines of the FWS.log file
    print $fws->tailFile( lines => 50, fileName => $fws->{fileSecurePath} . "/FWS.log" );


Append something to the FWS.log file if FWSLogLevel is set to 1 which is default.

    # Soemthing is happening
    $fws->FWSLog("this is happening\nthis is a new log line");

If a multi line string is passed it will break it up in to more than one log entries.


Append something to the SQL.log file if SQLLogLevel is set to 1 or 2. Level 1 will log anything that updates a database record, and level 2 will log everything. In good practice this should not be used, as all SQL statements are ran via the runSQL method which applies SQLLog.

    # Soemthing is happening
    $fws->SQLLog( $theSQLStatement );


Nate Lewis, <nlewis at>


Please report any bugs or feature requests to bug-fws-v2 at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc FWS::V2::File

You can also look for information at:


Copyright 2013 Nate Lewis.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.