IO_Inputfile = "********"; $this->IO_Outputfile = "********"; $this->IO_Logfile = "********"; $this->IO_inputFileHandle = ""; $this->IO_outputFileHandle = ""; $this->IO_logFileHandle = ""; $this->IO_returnString = ""; // this could be done with multidimensional arrays, also, // but I find this "explicit" option more clear // openFilesArray : keeps track of which files are open to // prevent re-opening, and for closing the files afterwards $this->openFilesArray = array( "inputfile" => "*****", "inputfile_status" => "closed", "outputfile" => "*****", "outputfile_status" => "closed", "logfile" => "*****", "logfile_status" => "closed"); if (!empty($this->IO_inputFileHandle)) { fclose($this->IO_inputFileHandle); } } // destructor function __destruct() { // close all open files ! ! ! ! if ($this->openFilesArray["inputfile_status"] == 'open') { fclose($this->IO_inputFileHandle); } if ($this->openFilesArray["outputfile_status"] == 'open') { fclose($this->IO_outputFileHandle); } if ($this->openFilesArray["logfile_status"] == 'open') { fclose($this->IO_logFileHandle); } } public function setInputFilePath ($inputPath) { if (is_file($inputPath)) { $this->openFilesArray["inputfile"] = $inputPath; $this->IO_returnString = "inputfile is set to " . $inputPath; } else { $this->IO_returnString = "ERROR : " . $inputPath ." for inputfile is not a valid path/filename, or file is not accessible from within this PHP script."; } return ($this->IO_returnString); } public function setOutputFilePath ($outputPath) { if (is_file($outputPath)) { $this->openFilesArray["outputfile"] = $outputPath; $this->IO_returnString = "outputfile is set to " . $outputPath; } else { $this->IO_returnString = "ERROR : " . $outputPath ." for outputfile is not a valid path/filename, or file is not accessible from within this PHP script."; } return ($this->IO_returnString); } public function setLogFilePath ($logPath) { if (is_file($logPath)) { if ($this->openFilesArray["inputfile_status"] == 'open') { fclose($this->IO_inputFileHandle); } $this->openFilesArray["logfile"] = $logPath; $this->IO_returnString = "logfile is set to " . $logPath; } else { $this->IO_returnString = "ERROR : " . $logPath ." for logfile is not a valid path/filename, or file is not accessible from within this PHP script."; } return ($this->IO_returnString); } public function getInputFilePath () { return($this->openFilesArray["inputfile"] ); } public function getOutputFilePath () { return($this->openFilesArray["outputfile"] ); } public function getLogFilePath () { return($this->openFilesArray["logfile"] ); } public function readLineFromInput () { if ( ($this->openFilesArray["inputfile_status"]) <> "open") { // we'll have to open the file first // remark : b added to file modus, to force binary mode for platform independence $this->IO_inputFileHandle = fopen($this->openFilesArray["inputfile"], "rb"); $this->openFilesArray["inputfile_status"]= "open"; } if (feof($this->IO_inputFileHandle)) { $IO_returnString = "no more input/end of file"; } else { $IO_returnString = fgets($this->IO_inputFileHandle,4096); } return ($IO_returnString); } public function writeLineToLog () { if ( ($this->openFilesArray["logfile_status"]) <> "open") { // we'll have to open the file first // remark : b added to file modus, to force binary mode for platform independence $this->IO_logFileHandle = fopen($this->openFilesArray["logfile"], "wb"); $this->openFilesArray["logfile_status"]= "open"; } // write } public function writeLineToOutput ($outputline) { if ( ($this->openFilesArray["outputfile_status"]) <> "open") { // we'll have to open the file first // remark : b added to file modus, to force binary mode for platform independence $this->IO_outputFileHandle = fopen($this->openFilesArray["outputfile"], "wb"); $this->openFilesArray["outputfile_status"]= "open"; } fwrite($this->IO_outputFileHandle,$outputline); } } ?>