All pastes #925026 Raw Edit

Something

public php v1 · immutable
·published 2008-03-01 22:32 UTC
rendered paste body
<?php/** * eiaf.class.php - Everything Is A file class * Class for handling and managing a filesystem via PHP * @author Per Sikker Hansen <per@sikker-hansen.dk> * @version 1.0.0 * @license http://gnu.org/licenses/lgpl.txt/ GNU Lesser General Public License (LGPL) */class eiaf {public $eiafconfig = array(	"rootdir" => "data/",	"showerrors" => "no",		"del404" => "<span style=\"font-weight:bold;\">[eiaf.class.del]</span> $time ERROR: File <span style=\"font-weight:bold;\">\"$eiafconfig[rootdir]$source\"</span> not found<br/>\n",	"get404" => "<span style=\"font-weight:bold;\">[eiaf.class.get]</span> $time ERROR: File <span style=\"font-weight:bold;\">\"$eiafconfig[rootdir]$source\"</span> not found<br/>\n",	"put404" => "<span style=\"font-weight:bold;\">[eiaf.class.put]</span> $time ERROR: File <span style=\"font-weight:bold;\">\"$eiafconfig[rootdir]$source\"</span> not found<br/>\n",	"mv404" => "<span style=\"font-weight:bold;\">[eiaf.class.mv]</span> $time ERROR: File <span style=\"font-weight:bold;\">\"$eiafconfig[rootdir]$source\"</span> not found<br/>\n",	"destinationexists" => "<span style=\"font-weight:bold;\">[eiaf.class.mvdir]</span> $time ERROR: Folder <span style=\"font-weight:bold;\">\"$eiafconfig[rootdir]$source\"</span> not found<br/>\n",	"mvdir404" => "<span style=\"font-weight:bold;\">[eiaf.class.mvdir]</span> $time ERROR: Directory <span style=\"font-weight:bold;\">\"$eiafconfig[rootdir]$source\"</span> not found<br/>\n",	"direxists" => "<span style=\"font-weight:bold;\">[eiaf.class.putdir]</span> $time ERROR: Directory <span style=\"font-weight:bold;\">\"$eiafconfig[rootdir]$source\"</span> already exists<br/>\n",	"dirnotempty" => "<span style=\"font-weight:bold;\">[eiaf.class.deldir]</span> $time ERROR: Directory <span style=\"font-weight:bold;\">\"$eiafconfig[rootdir]$source\"</span> is not empty</br>\n",	"dir404" => "<span style=\"font-weight:bold;\">[eiaf.class.deldir]</span> $time ERROR: Directory <span style=\"font-weight:bold;\">\"$eiafconfig[rootdir]$source\"</span> not found<br/>\n",);		function error($message, $source){		$time = time();		$error = $message;		if($this->eiafconfig["showerrors"]=="yes"){			$this->put("errors.log", $error, "append");			$return = $error;		}else{			$this->put("errors.log", $error, "append");			$return = false;		}		return $return;	}	    function get($source){		if(file_exists($this->eiafconfig["rootdir"].$source)){			$return = file_get_contents($this->eiafconfig["rootdir"].$source);		}else{			$return = $this->error($this->eiafconfig["get404"], $source);		}		return $return;    }        function put($source, $input, $method){ 		if(file_exists($this->eiafconfig["rootdir"].$source) || $method=="create"){						switch($method){				case "append":					$mode = "a";					break;				case "prepend":					$mode = "r+";					break;				case "rewrite":					$mode = "w";					break;				case "create":					$mode = "x";					break;			}			$stream = fopen($source, $mode);			fputs($stream, $input);			fclose($stream);		}else{			$return = $this->error($this->eiafconfig["put404"], $source);		}		return $return;	    }	function del($source){		if(file_exists($this->eiafconfig["rootdir"].$source)){			unlink($this->eiafconfig["rootdir"].$source);			$return = true;		}else{			$return = $this->error($this->eiafconfig["del404"], $source);		}		return $return;	}		function mv($source, $destination){		if(file_exists($this->eiafconfig["rootdir"].$source)){			if(!file_exists($this->eiafconfig["rootdir"].$destination)){				$data = $this->get($source);				$this->put($destination, $data, "create");				unlink($source);				$return = true;			}else{				$return = $this->error($this->eiafconfig["destinationexists"], $destination);			}		}else{			$return = $this->error($this->eiafconfig["mv404"], $source);		}		return $return;	}		function mvdir($source, $destination){		if(file_exists($this->eiafconfig["rootdir"].$source)){			if(!file_exists($this->eiafconfig["rootdir"].$destination)){				rename($source, $destination);				$return = true;			}else{				$return = $this>error($this->eiafconfig["destinationexists"], $destination);			}		}else{			$return = $this->error($this->eiafconfig["mvdir404"], $destination);		}		return $return;	}		function putdir($destination){			if(!file_exists($this->eiafconfig["rootdir"].$destination)){			mkdir($this->eiafconfig["rootdir"].$destination);			$return = true;		}else{			$return = $this->error($this->eiafconfig["direxists"], $destination);		}		return $return;	}		function deldir($source, $force="no"){		if(file_exists($source)){			if(strrpos($source, '/') == strlen($source) - 1){				$slash = null;			}else{				$slash = "/";			}			if(!glob($this->eiafconfig["rootdir"].$source.$slash."*")){				rmdir($source);				$return = true;			}elseif($force="yes"){				foreach(glob($this->eiafconfig["rootdir"].$source.$slash."*") as $filename){					$this->del($filename);				}				rmdir($source);				$return = true;			}else{				$return = $this->error($this->eiafconfig["dirnotempty"], $source);			}		}else{			$return = $this->error($this->eiafconfig["dir404"], $source);		}		return $return;	}	}?>