Location: PHPKode > scripts > F-ystem Support Module > f-ystem-support-module/function_usage.txt

	F-ystem Version 1 by Skorch
	http://phpmysql.12feetunder.com/support/?cat=6 Online F-ystem Support & Pointers

This class is meant to deal with files. It will dump and exit if you try to load a dir. If you need directory support check out Dirty Dirz also by Skorch. This class will change permissions, if needed, open a text-based file and read it, copy it or write to it.

It's the backbone of all of my feed generators. It could also be used to set up flat-file databases, Dirty Dirz would be a nice addition being that these two classes are designed to "interact". 


	function fystem($target_path,$file_mode) -> constructor function
$target_path should be a string identifying what file(and it's placement in your structure) you want to read or write too. $file_mode is the mode that PHP uses to open the file. You have three choices r = read file, w = write to file and a = append to file. Append adds information to end of file. Write truncates file to zero length then writes information to file. read reads files. If you add a plus at the end of each letter you will have enabled the opposite mode(write is the opposite of read and vice versa. append is a special write mode)


	function prep($string,$copy_source) -> preset wryt mode settings
$string will be prepared to be written to a file if in write mode. This method is irrelevant if you are just reading a file. $copy_source will be defined from your root folder(or the one you alternately specified using the settings file) if you want to write to a file in a folder the string for this var should be 'folder/file.ext' 
If you do not run this function before grabber, wryt mode only, you will get error code 001 when you try to use the grabber method.


	function grabber($do_this) -> Main Function
This method uses values from when you created the object(fystem) and prepped it(if writing to file). If the inputted values were incorrect you might experience erratic behaviour. 

This is how read/write errors are avoided by this class. If you have write only('w') or append only('a') mode set and try to read file grabber() resets $this->data['mode'] to read and write mode('r+') from read only('r') mode. If you have read only mode('r') set and try to write to a file $this->data['mode'] is reset to read/write mode('r+') The file in this case will be truncated to zero length.
$do_this is either 'read' or 'wryt'

 if an error was encountered an error code is returned

 If you read a file then that file's contents are returned

 If you wrote to a file 13 is returned


	F-ystem usage examples


  Write to the file.(the index.html for your root folder)

$target_path = 'index.html'; // write to index.html, in root
// write to folder, in root, named 'xml'(I must exist) containing file 'feed.xml'
// alt path example -> $target_path = 'xml/feed.xml';

$file = new fystem($target_path,'w+');//write and read mode
$file->prep('Write this string to file',''); // create blank file, no copy

IF($string !== 13){
echo 'Write error';}ELSE
echo 'Successful write';


   Read file list.txt in root folder

$target_path = 'list.txt';
$file = new fystem($target_path,'r+'); // read and write mode
// read list.txt, in root

IF($string !=== 101){
echo $string;
echo 'File read error';

Return current item: F-ystem Support Module