我正在尝试使用此代码删除2个文件夹中所有超过x天的文件,但出现错误:
PHP解析错误:语法错误,第6行的E:\ home \ ca \ web \ cm \ cache.php中出现意外的T_PUBLIC
为什么?
<?php
$pastas = array("gallery-images/","resources/cache/");
foreach($pastas as $pasta){
$this->deleteFrom($pasta);
}
public function deleteFrom($path){
$expiretime=10080; //expire time in minutes, 7 days = 7*24*60
$tmpFolder=$path.'/';
$fileTypes="*.*";
foreach (glob($tmpFolder . $fileTypes) as $Filename) {
// Read file creation time
$FileCreationTime = filectime($Filename);
// Calculate file age in seconds
$FileAge = time() - $FileCreationTime;
// Is the file older than the given time span?
if ($FileAge > ($expiretime * 0)){
// Now do something with the olders files...
echo "The file $Filename is older than $expiretime minutes\n";
//delete files:
unlink($Filename);
}
}
}
?>
您的函数定义不在类中,因此您需要删除PUBLIC
public function deleteFrom($path){
到
function deleteFrom($path){
同样$this->
是不正确的,您需要删除它们并以以下形式调用该函数:
deleteFrom($pasta);
检查此处如何在PHP中使用Public,Private等http://php.net/manual/en/language.oop5.visibility.php
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句