[PHP]
<?php
class FileRemoval {
var $fileNameArray, $isRemoved, $errorMsg = '';
function FileRemoval() {
$this->fileNameArray = array();
$this->isRemoved = 0;
}
function getErrorMsg() {
return $this->errorMsg;
}
function getIsRemoved() {
return $this->isRemoved;
}
function setFileNameArray() {
global $argv;
$junk = array_shift($argv); // LOB OFF FIRST ARRAY ELEMENT YOU
DON'T NEED THE SCRIPT NAME
$this->fileNameArray = $argv;
}
function remove() {
$this->setFileNameArray();
if (sizeof($this->fileNameArray) == 0) {
$this->isRemoved = 0;
$this->errorMsg = "No files provided for removal\n";
}
if (!$this->errorMsg) {
foreach ($this->fileNameArray as $val) {
if (!file_exists($val) || strlen($val) == 0) {
$this->isRemoved = 0;
$this->errorMsg = "File: $val does not exist\n";
echo $this->errorMsg;
break;
}
}
if (!$this->errorMsg) @unlink($file);
}
if (!$this->errorMsg) $this->isRemoved = 1;
}
function writeErr() {
if ($this->errorMsg) {
$fileID = fopen('./cmds.err', 'r') or die("Could not find error
log");
$myErr = '[' . date("%d/%b/%Y:%H:%I:%S"). ']' . $this->errorMsg .
"\n";
fputs($fileID, $myErr);
fflush($fileID);
fclose($fileID);
fwrite(STDOUT, $myErr);
}
}
}
$fileRemoval =& new FileRemoval();
$fileRemoval->remove();
echo "**" . $fileRemoval->getIsRemoved();
if (!$fileRemoval->getIsRemoved()) $fileRemoval->writeErr();
$fileRemoval = null;
?>
[/PHP]
I am writing a very simple PHP script that will be called from a
front-end bash script (and a TCL script - long story) that will remove
a list of files passed into the PHP script as $argv array. Problem is
right now that I am unable to get it to write to the error log (see
method writeErr) nor am I able to produce the error in stdout (again
see method writeErr), I get the error message:
Supplied argument is not a valid File-Resource handle in line 53:
line 53: fwrite(STDOUT, $myErr);
I am not sure now how to do this so I can use some help.
Thanx
Phil