if($file != "." && $file != "..") {
$diff=get_time_difference(time(),filectime($dir.$file)) //getting the file created time
if ($diff['hours']>1){ //if more than 1 hours of the created time, delete
chmod($dir.$file, 0777);
unlink($dir.$file) or DIE("couldn't delete $dir$file<br />");
}
function destroy($dir) {
echo "destroying directory '$dir' <br/>";
$mydir = opendir($dir);
while(false !== ($file = readdir($mydir))) {
echo "readdir gives '$file' <br/>";
if($file != "." && $file != "..") {
$fullfile = $dir . $file;
echo "full file name is '$fullfile' <br/>";
$diff=get_time_difference(time(),filectime($fullfile));//getting the file created time
$diffhours = $diff['hours'];
echo "age of $fullfile is $diffhours hours<br/>";
if ($diffhours>3){//if more than 3 hours of the created time, delete
echo "trying to delete '$fullfile' <br/>";
$ok = chmod($fullfile, 0777);
echo "chomd --> $ok <br/>";
$ok = unlink($fullfile);
echo "unlink --> $ok <br/>";
}
}
}
closedir($mydir);
}
http://www.tizag.com/phpT/filedelete.php
In Windows environments you may try
<?php
chown($TempDirectory."/".$
unlink($TempDirectory."/".
?>
to change permisions to grant deletion of the file.
Hope that helps,
Pancho