days, date('Y')); $end = mktime(0, 0, 0, date('m'), date('d'), date('Y')); //echo date('Y-m-d h:i:s', $start), "\n"; //echo date('Y-m-d h:i:s', $end), "\n"; foreach (scandir($dir) as $file) { if ($file == '.' || $file == '..' || substr($file,0,1) == '.') continue; $filename = $dir . '/' . $file; if (is_dir($filename)) { $this->scanDir($filename); continue; } $lastmod = filemtime($filename); // echo date('Y-m-d h:i:s', $lastmod), "\n"; if ($lastmod >= $start && $lastmod < $end) { Yii::log('Addding watermark to file '.$filename.', modified at '.date('Y-m-d h:i:s', $lastmod),CLogger::LEVEL_INFO,'waterMark'); $this->mark($filename); $data = file_get_contents($filename); unlink($filename); file_put_contents($filename,$data); chmod($filename,0777); @touch($filename, $lastmod); // echo $filename, "\n"; } } } public function actionAdd($days=1) { $this->days = (int)$days; $uploads = realpath(Yii::getPathOfAlias('application') . '/../uploads'); Yii::log('waterMark command started, with days='.$days,CLogger::LEVEL_INFO,'waterMark'); $start = mktime(0, 0, 0, date('m'), date('d') - $this->days, date('Y')); $end = mktime(0, 0, 0, date('m'), date('d'), date('Y')); Yii::log('Adding watermarks to files in directory: "'.$uploads.'" form '. date('Y-m-d h:i:s', $start). " to ". date('Y-m-d h:i:s', $end),CLogger::LEVEL_INFO,'waterMark'); $this->scanDir($uploads); } }