The Keyword search is currently down, so I hope this wasn't answered previously.
Does anyone know if there is an issue with clearstatcache() or am I doing something wrong?
Here is a bit of linear code to illustrate my issue...
When the file doesn't exist, this is what I get...
The file: testfile.txt does not exist. Creating it.
Filesize: 0
Filesize: 0
Warning: fread() [function.fread]: Length parameter must be greater than 0. in C:\Program Files\Apache Group\Apache2\htdocs\testing\file_io2.php on line 27
Data after write:
Data after write with specific read size: This is a test.
This is the data that is REALLY in the testfile.txt file: This is a test.
When the file does exist, this is what I get...
Filesize: 15
Data before write: This is a test.
Filesize: 15
Data after write: This is a test.
Data after write with specific read size: This is a test.This is a test.
This is what is REALLY in the testfile.txt file: This is a test.This is a test.
Does anyone know if there is an issue with clearstatcache() or am I doing something wrong?
Here is a bit of linear code to illustrate my issue...
Code:
$filename = "testfile.txt";
if (! is_file($filename))
{
echo "<b>The file: $filename does not exist. Creating it.</b>\n<br><br>";
}
$fh = fopen($filename, "a+") or die ("The file: $filename could not be created or opened.");
$filesize = filesize($filename);
echo "<b>Filesize:</b> $filesize\n<br><br>";
if ($filesize > 0)
{
$readdata = fread($fh, filesize($filename));
echo "<b>Data before write:</b> $readdata\n<br><br>";
}
$writeit = fwrite ($fh, "This is a test.");
clearstatcache(); //filesize() supposedly won't work twice unless you clearstatcache()
rewind($fh); //two freads won't work unless you rewind the pointer
$filesize = filesize($filename);
echo "<b>Filesize:</b> $filesize\n<br><br>";
$readdata = fread($fh, $filesize);
echo "<b>Data after write:</b> $readdata\n<br><br>";
rewind($fh);
$readdata = fread($fh, 1024);
echo "<b>Data after write with specific read size:</b> $readdata\n<br><br>";
fclose ($fh);
$str = file_get_contents($filename);
echo "<b>This is what is REALLY in the $filename file:</b> ".$str."<br>";
When the file doesn't exist, this is what I get...
The file: testfile.txt does not exist. Creating it.
Filesize: 0
Filesize: 0
Warning: fread() [function.fread]: Length parameter must be greater than 0. in C:\Program Files\Apache Group\Apache2\htdocs\testing\file_io2.php on line 27
Data after write:
Data after write with specific read size: This is a test.
This is the data that is REALLY in the testfile.txt file: This is a test.
When the file does exist, this is what I get...
Filesize: 15
Data before write: This is a test.
Filesize: 15
Data after write: This is a test.
Data after write with specific read size: This is a test.This is a test.
This is what is REALLY in the testfile.txt file: This is a test.This is a test.