Version: 00.00.01

Type: Class

Category: File Management

License: GNU General Public License

Description: This is a little file filter that you can use for your file management projects.



<?
        /**
	 * --------------------------------------------------
	 * Copyright 05/01/2002 erick.gonzalez@softtek.com
	 * FileFilter class
	 * --------------------------------------------------
	 * Filters any file declared
	 * @author		erick.gonzalez@softtek.com
	 * @version		00.00.01
	 */
	class FileFilter {
		/** The file types' list for filtering */
		var $objcFilterList;
		
		/**
		 * Creates an instance of the FileFilter class and declares 
		 * the variable objcFilterList as an Array
		 */
		function FileFilter() {
			$this->objcFilterList = Array();
		}
		
		/**
		 * Adds a new file type to the types' array
		 * @param		$saType		The new file type
		 */
		function addType($saType) {
			if ($saType != null) {
				array_push($this->objcFilterList, $saType);
			}
		}
		
		/**
		 * Returns true if the file type is valid, false if it doesn't happen
		 * @param		$saType		The file type
		 * @returns		true if the file type is valid, false if it doesn't happen
		 */
		function isValidType($saType) {
			$blIsValid = false;
			
			if ($saType != null) {
				
				for ($i = 0; $i < count($this->objcFilterList); $i++) {
					if ($saType == $this->objcFilterList[$i]) {
						$blIsValid = true;
					}
				}
			}
			
			return $blIsValid;
		}
		
		/**
		 * Returns true if the fileis valid, false if it doesn't happen
		 * @param		$saType		The file name
		 * @returns		true if the file is valid, false if it doesn't happen
		 */
		function isValidFile($saFile) {
			$blIsValid = false;
			$slFileType = "";
			
			if ($saFile != null) {
				if (count($this->objcFilterList) > 0) {
					$saFileType = $this->returnFileType($saFile);
					$blIsValid = $this->isValidType($saFileType);
				} else {
					$blIsValid = true;
				}
			}
			
			return $blIsValid;
		}
		
		/**
		 * Returns the file type from the given file name
		 * @param		$saFile		The given file name
		 * @returns		the file type
		 */
		function returnFileType($saFile) {
			$slFileType = "";
			
			if ($saFile != null) {
				$slFileType = substr($saFile, strpos($saFile, "."), strlen($saFile));
			}
			
			return $slFileType;
		}
		
		/**
		 * Returns the file types' array
		 */
		function returnTypes() {
			return $this->objcFilterList;
		}
	}
?>