Hello,
I am creating a class which creates a temporary file to write data into in __construct();
After the script is finished I'd like __destruct() to delete the temporary file.
However, I get a file not found error when the file is very clearly there. If I try and delete in the constructor it deletes fine though so I'm fairly certain it's not a path issue.
Here is my code:
<?php
class myClass
{
private $cache;
private $cachefile;
public function __construct($cachef)
{
//create an empty cache ready for writing
$this->cache = fopen($cachef, "w");
//declare cachefile for class
$this->cachefile = $cachef;
}
public function __destruct()
{
//close writing to file
fclose($this->cache);
//delete file
unlink($this->cachefile);
}
}
?>
Thanks in advance for any help.