I am trying to make a object/class that will send data from forms and other sources into a flatfile system. Basicly I'm asking for opinions on whether my system will work or will it eventually become too slow and hard to manage.
Example of the file that data is stored in:
1|some data2|some data3
2|some data2|some data3
Here is the code, its not complete but you might get an idea what I want to accomplish:
class ReadWrite
{
var $_F = array();
var $error = array();
function ReadWrite($file)
{
$this->_F = $file;
$this->_FileArray = file($file);
}
// Does the actual writing to file
//
function _write($quary)
{
if(is_array($quary))
$quary = implode("",$quary);
$output = $quary;
$output = stripslashes($output);
$fp = fopen($this->_F, "w+");
if (flock($fp, LOCK_EX))
{ // do an exclusive lock
if(!fwrite($fp, "$output"))
$this->errors[] = "Unable to write file";
flock($fp, LOCK_UN); // release the lock
chmod($fthis->_F, 0777);
} else {
$this->errors[] = "Couldn't lock the file !";
}
fclose($fp);
return $output;
}
// Cleans the bad crap from users input
//
Function _Cleaner($quary)
{
if( is_array($quary) )
{
while( list($k, $v) = each($quary) )
{
if( is_array($quary[$k]) )
{
while( list($k2, $v2) = each($quary[$k]) )
{
$quary[$k][$k2] = htmlspecialchars(trim($v2),ENT_QUOTES);
$quary[$k][$k2] = str_replace("|", "|",$v2);
}
@reset($quary[$k]);
}
else
{
$quary[$k] = htmlspecialchars(trim($v),ENT_QUOTES);
$quary[$k] = str_replace("|", "|",$v);
}
}
@reset($quary);
}
return $quary;
}
// Breaks the info store in a array into useable pieces
//
function _parts($value)
{
$value = addslashes(trim($value));
$parts = explode("|",$value);
$clean = $this->_Cleaner($parts);
return $clean;
}
// Procosses Delete Data Command
//
function delete($delete)
{
foreach($this->_FileArray as $value)
{
$y = $this->_parts($value);
if (!in_array($y[0],$delete))
{
$tmp[] = $value;
}
}
$vars = $this->_write($tmp);
return $vars;
}
}
########################################
$test = new ReadWrite("tEMP/links.txt");
$delete = array();
$delete[] = "one";
//die(print_r($delete));
print($test->delete($delete));
?>