PHP 4.1.2
@fputs($fileID, $emailTo);
@fflush($fileID);
@rewind($fileID);
if ((int)filesize("$bundleEmailFilePath/$bundleEmailFileName") === 0) @file_put_contents("$bundleEmailFilePath/$bundleEmailFileName", $emailTo);
if ((int)filesize("$bundleEmailFilePath/$bundleEmailFileName") === 0) {
$this->isSuccessful = false;
$this->setErrorArray(array('action' => "Could not write onto bundling file \"$bundleEmailFilePath/$bundleEmailFileName\""));
}
I am able to add content to a flat file, however, I am not only unable to ever read the contents of that file, no matter what I use, whether fread(), file() or file_get_contents() (function below), but even filesize() produces inaccurate results inasmuch as it says 0 every time (I can see content in the file using pico, pine, GEdit and even the Unix "more" command!!)
Bottom line: I am completely unable to read contents of a file, nor determine file size, using PHP 4.1.2 and this is a requirement!
Please help!!
Function for file_get_contents() that I wrote for PHP 4.1.2:
if (!function_exists('file_get_contents')) {
if (preg_match('/^5\.[1-9]+\.?[0-9]*$/i', trim(phpversion()))) { // file_get_contents FOR PHP VERSION 5.1.0+ IF FUNCTION UNAVAILABLE
/**
* Retrieve file contents into a string. This function exists only in PHP versions 4.3.0+
*
* @access public
* @param mixed $filePath
* @param boolean $willUseIncludePath (default false)
* @param resource $context (optional)
* @param int $offset (optional)
* @param int $maxLength (optional)
* @internal $context is available in PHP versions 5.0.0+. $offset and $maxLength is available in PHP versions 5.1.0+
* @link http://us3.php.net/manual/en/function.file-get-contents.php
* @see link in PHP manual explaining file_get_contents
*/
function file_get_contents($filePath, $willUseIncludePath = false, $context = '', $offset = '', $maxLength = '') {
$fileID = @fopen($filePath, 'rb', $willUseIncludePath, $context);
if ($fileID && is_numeric($maxLength) && is_numeric($offset)) {
$contents = @fread($fileID, $maxLength - $offset);
} elseif ($fileID && is_numeric($maxLength)) {
$contents = @fread($fileID, $maxLength);
} elseif ($fileID) {
$contents = @fread($fileID, filesize($filePath));
}
if ($fileID) @fclose($fileID);
if (!$contents && !$_ENV['windir']) $contents = exec("more $filePath");
return $contents;
}
} elseif (preg_match('/^5\.0?\.?[0-9]*$/i', trim(phpversion()))) { // file_get_contents FOR PHP VERSION 5.0.0+ IF FUNCTION UNAVAILABLE
function file_get_contents($filePath, $willUseIncludePath = false, $context = '') {
$fileID = @fopen($filePath, 'rb', $willUseIncludePath, $context);
if ($fileID) {
$contents = @fread($fileID, filesize($filePath));
@fclose($fileID);
}
if (!$contents && !$_ENV['windir']) $contents = exec("more $filePath");
return $contents;
}
} else { // ALL OTHER VERSIONS OF file_get_contents
function file_get_contents($filePath, $willUseIncludePath = false) {
$fileID = @fopen($filePath, 'rb', $willUseIncludePath);
if ($fileID) {
$contents = @fread($fileID, filesize($filePath));
@fclose($fileID);
}
if (!$contents && !$_ENV['windir']) $contents = exec("more $filePath");
return $contents;
}
}
}
Thanx
Phil