public function index() { $path = TMPL_PATH . 'Home/pigcms'; foreach (glob($path . '/*') as $k => $item) { if (is_file($item)) { if (strstr($item, 'about')) { $list[$k]['name'] = '关于我们'; $list[$k]['m_name'] = $item; $list[$k]['m_time'] = filemtime($item); $list[$k]['c_time'] = filectime($item); $list[$k]['a_time'] = fileatime($item); } elseif (strstr($item, 'fc')) { $list[$k]['name'] = '功能介绍'; $list[$k]['m_name'] = $item; $list[$k]['m_time'] = filemtime($item); $list[$k]['c_time'] = filectime($item); $list[$k]['a_time'] = fileatime($item); } elseif (strstr($item, 'price')) { $list[$k]['name'] = '资费'; $list[$k]['m_name'] = $item; $list[$k]['m_time'] = filemtime($item); $list[$k]['c_time'] = filectime($item); $list[$k]['a_time'] = fileatime($item); } elseif (strstr($item, 'help')) { $list[$k]['name'] = '帮助'; $list[$k]['m_name'] = $item; $list[$k]['m_time'] = filemtime($item); $list[$k]['c_time'] = filectime($item); $list[$k]['a_time'] = fileatime($item); } } } $this->assign('list', $list); $this->display(); }
public static function sweep() { $watch_path = LookoutController::watchPath(); $inactive_users = array(); $orig_dir = getcwd(); chdir($watch_path); $worked = false; $watch_files = glob('*.sess'); foreach ($watch_files as $file) { $file_access_time = fileatime($file); $current_time = time(); $inactive = $current_time - $file_access_time > MAX_INACTIVE_TIME; if ($inactive) { $userid = explode('.', $file); array_push($inactive_users, $userid[0]); } $worked = true; } chdir($orig_dir); if (sizeof($inactive_users) > 0) { LookoutController::deleteInactiveWatch($inactive_users); AuthenticationController::autoLogout($inactive_users); $worked = true; } return $worked; }
public function execute() { global $CFG, $DB; $deleted_files_num = 0; $deleted_filesize_num = 0; $undeleted_filesize_num = 0; $directory = $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache'; $now = strtotime('now'); $handle = opendir($directory); while (FALSE !== ($item = readdir($handle))) { $path = $directory . '/' . $item; if ($item != '.' || $item != '..') { if ($now >= fileatime($path) + 21600 || $now >= filectime($path) + 21600 || $now >= filemtime($path) + 21600) { $deleted_files_num++; $deleted_filesize_num += filesize($path); unlink($path); } else { $undeleted_filesize_num += filesize($path); } } } closedir($handle); echo "... Deleted files: " . $deleted_files_num . " \r\n"; echo "... Free Space: " . number_format($deleted_filesize_num / 1048576, 2, '.', '') . " MB \r\n"; echo "... Busy Space: " . number_format($undeleted_filesize_num / 1048576, 2, '.', '') . " MB \r\n"; }
public function getContent() { $url = $this->getConfigVar('feed_url'); if ($url == '') { return 'Enter a RSS Feed in this Widget configuration.'; } // Cache File path $cacheFile = PATH_site . 'typo3temp/mydashboard' . substr(md5($url . $this->getConfigVar('feed_title')), 0, 15) . '.cache'; // Update rules $updateRSS = isset($_POST['ajax']) && isset($_POST['action']) && $_POST['action'] == 'refresh'; // Load a Cache File if (file_exists($cacheFile) && !$updateRSS) { $fileinfo = fileatime($cacheFile); if ($fileinfo > time() - (int) $this->getConfigVar('cache_time_h')) { $data = $this->loadRSSData($cacheFile); return $this->renderRSSArray($data); } # if } # if // Load the rss2array class and fetch the RSS Feed require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('mydashboard', 'widgets/helper/rss2array.php'); $rss_array = rss2array($url); // Safe the Feed in a Cache File $this->safeRSSData($cacheFile, $rss_array); return $this->renderRSSArray($rss_array); }
public function index($id=null) { if ($id==null) { $data=PATH_APP.'data/inventory.data'; $maxtime=(isset($_GET['refresh'])) ? -300 : 300; if ((file_exists($data)) && (fileatime($data)>(time()-$maxtime))) $slices=unserialize(file_get_contents($data)); else { $slices=$this->slicehost->slices; file_put_contents($data,serialize($slices)); } return array( 'slice' => null, 'slices' => $slices ); } $slice=new SliceResource($this->slicehost,$id); return array( 'slice' => $slice, 'slices' => null, 'images' => $this->slicehost->images, 'backups' => $this->slicehost->backups, 'flavors' => $this->slicehost->flavors ); }
public function testComprobarArchivos() { $CarpetaRespaldos = POS_PATH_TO_SERVER_ROOT . "/../static_content/db_backups/"; $nArchivos = 0; $directorio = dir($CarpetaRespaldos); $d1 = date("d", time()); //Dia Actual $d2 = null; $m1 = date("m", time()); //Mes actual $m2 = null; $a1 = date("y", time()); //Año actual $a2 = null; while ($archivo = $directorio->read()) { //Cada nombre de archivo debe medir 30 caracteres if (strlen($archivo) > 2) { $d2 = date("d", fileatime($CarpetaRespaldos . $archivo)); $m2 = date("m", fileatime($CarpetaRespaldos . $archivo)); $a2 = date("y", fileatime($CarpetaRespaldos . $archivo)); if (substr($archivo, 10, 14) == "_pos_instance_" && substr($archivo, strlen($archivo) - 4, 4) == ".sql") { $nArchivos++; } if ($d1 > $d2 + 7 || $m1 > $m2 || $a1 > $a2 && (substr($archivo, 10, 14) == "_pos_instance_" && substr($archivo, strlen($archivo) - 3, 3) == "sql")) { //Comprueba que se borró correctamente el archivo viejo $this->assertTrue(unlink($CarpetaRespaldos . $archivo)); } } } $directorio->close(); }
public function build($file, $mode = false) { $files = $this->getBuilderArr($this->getBuilderJsonArr(), $file); if (count($files) == 0) { throw NGS()->getDebugException("Please add less files in builder"); } $options = array(); if ($mode) { $options["compress"] = true; } $this->lessParser = new \Less_Parser($options); $this->lessParser->parse('@NGS_PATH: "' . NGS()->getHttpUtils()->getHttpHost(true) . '";'); $this->lessParser->parse('@NGS_MODULE_PATH: "' . NGS()->getPublicHostByNS() . '";'); $this->setLessFiles($files); if ($mode) { $outFileName = $files["output_file"]; if ($this->getOutputFileName() != null) { $outFileName = $this->getOutputFileName(); } $outFile = $this->getOutputDir() . "/" . $outFileName; touch($outFile, fileatime($this->getBuilderFile())); file_put_contents($outFile, $this->lessParser->getCss()); exit; return true; } header('Content-type: ' . $this->getContentType()); echo $this->lessParser->getCss(); exit; }
public function listFile($pathname, $pattern = "*") { static $_listDirs = array(); $guid = md5($pathname . $pattern); if (!isset($_listDirs[$guid])) { $dir = array(); $list = glob($pathname . $pattern); foreach ($list as $i => $file) { $dir[$i]["filename"] = preg_replace("/^.+[\\\\\\/]/", "", $file); $dir[$i]["pathname"] = realpath($file); $dir[$i]["owner"] = fileowner($file); $dir[$i]["perms"] = fileperms($file); $dir[$i]["inode"] = fileinode($file); $dir[$i]["group"] = filegroup($file); $dir[$i]["path"] = dirname($file); $dir[$i]["atime"] = fileatime($file); $dir[$i]["ctime"] = filectime($file); $dir[$i]["size"] = filesize($file); $dir[$i]["type"] = filetype($file); $dir[$i]["ext"] = is_file($file) ? strtolower(substr(strrchr(basename($file), "."), 1)) : ""; $dir[$i]["mtime"] = filemtime($file); $dir[$i]["isDir"] = is_dir($file); $dir[$i]["isFile"] = is_file($file); $dir[$i]["isLink"] = is_link($file); $dir[$i]["isReadable"] = is_readable($file); $dir[$i]["isWritable"] = is_writable($file); } $cmp_func = create_function("\$a,\$b", "\r\n\t\t\t\$k = \"isDir\";\r\n\t\t\tif(\$a[\$k] == \$b[\$k]) return 0;\r\n\t\t\treturn \$a[\$k]>\$b[\$k]?-1:1;\r\n\t\t\t"); usort($dir, $cmp_func); $this->_values = $dir; $_listDirs[$guid] = $dir; } else { $this->_values = $_listDirs[$guid]; } }
/** * Gets last access time. * * @return DateTime */ public function getLastAccessedAt() { $timestamp = fileatime($this->pathname); $time = new DateTime(); $time->setTimestamp($timestamp); return $time; }
protected function doBuild($file) { $files = $this->getBuilderArr(json_decode(file_get_contents($this->getBuilderFile())), $file); if (!$files) { return; } $outDir = $this->getOutputDir(); $buf = ""; foreach ($files["files"] as $value) { $module = ""; if ($value["module"] == null) { $module = "ngs"; } $inputFile = realpath(NGS()->getCssDir($module) . "/" . trim($value["file"])); if (!$inputFile) { throw new DebugException($filePath . " not found"); } $buf .= file_get_contents($inputFile) . "\n\r"; } if ($files["compress"] == true) { $buf = $this->doCompress($buf); } touch($outDir . "/" . $files["output_file"], fileatime($this->getBuilderFile())); file_put_contents($outDir . "/" . $files["output_file"], $buf); }
/** * Clear cache post processor * * This method deletes all temporary files that are older than one month and * if the deletion of the whole cache is requested. * * @param object $params parameter array * @return void */ public function clearCachePostProc(&$params) { if ($params['cacheCmd'] !== 'all') { return; } $now = time(); foreach ($this->tempDirectories as $tempDirectory => $maxAge) { if (!is_dir($tempDirectory)) { continue; } $handle = opendir($tempDirectory); while (FALSE !== ($file = readdir($handle))) { if ($file === '.' || $file === '..') { continue; } if (is_file($tempDirectory . $file)) { // get last modification time $lastAccess = fileatime($tempDirectory . $file); $age = $now - $lastAccess; if ($age >= $maxAge) { unlink($tempDirectory . $file); } } } } }
function cleanup_location($temp_disk) { global $id; $list = scandir($temp_disk); if ($list === false) { return false; } $wait_seconds = 60; // After a minute of not being accessed or modified, // we assume that the file is an orphan. foreach ($list as $entry) { $path = "{$temp_disk}/{$entry}"; if (is_file($path)) { $access_interval = time() - fileatime($path); $modify_interval = time() - filemtime($path); if ($access_interval > $wait_seconds && $modify_interval > $wait_seconds) { syslog(LOG_WARNING, "get_archive.php?id={$id}: found what appears to be orphan file {$path}: has not been (accessed,modified) for ({$access_interval},{$modify_interval}) seconds. Deleting it."); if (unlink($path)) { syslog(LOG_ERR, "get_archive.php?id={$id}: error unlinking {$path}"); } } } } return true; }
public function cacheData($key, $value = '', $cacheTime = 0) { $filename = $this->_dir . $key . self::EXT; if ($value !== '') { if (is_null($value)) { return @unlink($filename); } $dir = dirname($filename); if (!is_dir($dir)) { mkdir($dir, 0777); } $cacheTime = sprintf('%011d', $cacheTime); return file_put_contents($filename, $cacheTime . json_encode($value)); } if (!is_file($filename)) { return FALSE; } $contents = file_get_contents($filename, true); $cacheTime = (int) substr($contents, 0, 11); $value = substr($contents, 11); if ($cacheTime != 0 && $cacheTime + fileatime($filename) < time()) { unlink($filename); return FALSE; } return json_decode($value, true); }
function find_old_files($dirname, $before_date) { $dir = new DirectoryIterator($dirname); foreach ($dir as $file) { if ($file->isDot()) { continue; } if ($file->getFilename() == 'kfm') { continue; } $fname = $dirname . '/' . $file->getFilename(); if (is_dir($fname)) { find_old_files($fname, $before_date); } else { $delete = fileatime($fname) < $before_date; if (!$delete) { continue; } $GLOBALS['deleted']++; $GLOBALS['saved'] += filesize($fname); echo date('Y-m-d', fileatime($fname)) . ' ' . $fname . '<br />'; unlink($fname); } } }
public function getLastAccessTime() { if (!$this->isExists()) { throw new FileNotFoundException($this->originalPath); } return fileatime($this->getPhysicalPath()); }
function get_recent_audiomark() { // get the most recent filename $files_in_directory = scandir(AUDIO_FOLDER); $recent_file_name = ''; $recent_file_access_time = 0; foreach ($files_in_directory as $file) { if ($file == '.' || $file == '..') { continue; } $file_time = fileatime(AUDIO_FOLDER . $file); if ($file_time > $recent_file_access_time) { $recent_file_access_time = $file_time; $recent_file_name = $file; } } // get file as binary string $filename = AUDIO_FOLDER . $file; try { $handle = fopen($filename, "rb"); $filecontent = fread($handle, filesize($filename)); fclose($handle); } catch (Exception $e) { echo 'Problem: ', $e->getMessage(), "\n"; } $filecontent = addslashes($filecontent); return $filecontent; }
public function listFile($pathname, $pattern = '*') { static $_listDirs = array(); $guid = md5($pathname . $pattern); if (!isset($_listDirs[$guid])) { $dir = array(); $list = glob($pathname . $pattern); foreach ($list as $i => $file) { $dir[$i]['filename'] = basename($file); $dir[$i]['pathname'] = realpath($file); $dir[$i]['owner'] = fileowner($file); $dir[$i]['perms'] = fileperms($file); $dir[$i]['inode'] = fileinode($file); $dir[$i]['group'] = filegroup($file); $dir[$i]['path'] = dirname($file); $dir[$i]['atime'] = fileatime($file); $dir[$i]['ctime'] = filectime($file); $dir[$i]['size'] = filesize($file); $dir[$i]['type'] = filetype($file); $dir[$i]['ext'] = is_file($file) ? strtolower(substr(strrchr(basename($file), '.'), 1)) : ''; $dir[$i]['mtime'] = filemtime($file); $dir[$i]['isDir'] = is_dir($file); $dir[$i]['isFile'] = is_file($file); $dir[$i]['isLink'] = is_link($file); $dir[$i]['isReadable'] = is_readable($file); $dir[$i]['isWritable'] = is_writable($file); } $cmp_func = create_function('$a,$b', '' . "\r\n" . ' $k = "isDir";' . "\r\n" . ' if($a[$k] == $b[$k]) return 0;' . "\r\n" . ' return $a[$k]>$b[$k]?-1:1;' . "\r\n" . ' '); usort($dir, $cmp_func); $this->_values = $dir; $_listDirs[$guid] = $dir; } else { $this->_values = $_listDirs[$guid]; } }
/** * collect all fileinformations of given file and * save them to the global fileinformation array * * @param string $file * @return boolean is valid file? */ protected function setFileInformations($file) { $this->fileInfo = array(); // reset previously information to have a cleaned object $this->file = $file instanceof \TYPO3\CMS\Core\Resource\File ? $file : NULL; if (is_string($file) && !empty($file)) { $this->fileInfo = TYPO3\CMS\Core\Utility\GeneralUtility::split_fileref($file); $this->fileInfo['mtime'] = filemtime($file); $this->fileInfo['atime'] = fileatime($file); $this->fileInfo['owner'] = fileowner($file); $this->fileInfo['group'] = filegroup($file); $this->fileInfo['size'] = filesize($file); $this->fileInfo['type'] = filetype($file); $this->fileInfo['perms'] = fileperms($file); $this->fileInfo['is_dir'] = is_dir($file); $this->fileInfo['is_file'] = is_file($file); $this->fileInfo['is_link'] = is_link($file); $this->fileInfo['is_readable'] = is_readable($file); $this->fileInfo['is_uploaded'] = is_uploaded_file($file); $this->fileInfo['is_writeable'] = is_writeable($file); } if ($file instanceof \TYPO3\CMS\Core\Resource\File) { $pathInfo = \TYPO3\CMS\Core\Utility\PathUtility::pathinfo($file->getName()); $this->fileInfo = array('file' => $file->getName(), 'filebody' => $file->getNameWithoutExtension(), 'fileext' => $file->getExtension(), 'realFileext' => $pathInfo['extension'], 'atime' => $file->getCreationTime(), 'mtime' => $file->getModificationTime(), 'owner' => '', 'group' => '', 'size' => $file->getSize(), 'type' => 'file', 'perms' => '', 'is_dir' => FALSE, 'is_file' => $file->getStorage()->getDriverType() === 'Local' ? is_file($file->getForLocalProcessing(FALSE)) : TRUE, 'is_link' => $file->getStorage()->getDriverType() === 'Local' ? is_link($file->getForLocalProcessing(FALSE)) : FALSE, 'is_readable' => TRUE, 'is_uploaded' => FALSE, 'is_writeable' => FALSE); } return $this->fileInfo !== array(); }
function rmdirr($dirname, $oc = 0) { // Sanity check if (!file_exists($dirname)) { return false; } // Simple delete for a file if (is_file($dirname) && time() - fileatime($dirname) > 3600) { return unlink($dirname); } // Loop through the folder if (is_dir($dirname)) { $dir = dir($dirname); while (false !== ($entry = $dir->read())) { // Skip pointers if ($entry === '.' || $entry === '..') { continue; } // Recurse rmdirr($dirname . '/' . $entry, $oc); } $dir->close(); } // Clean up if ($oc == 1) { return rmdir($dirname); } }
/** * 遍历目录内容 * @param string $dirName 目录名 * @param string $exts 读取的文件扩展名 * @param int $son 是否显示子目录 * @param array $list * @return array */ public static function tree($dirName = null, $exts = '', $son = 0, $list = array()) { if (is_null($dirName)) { $dirName = '.'; } $dirPath = self::dirPath($dirName); static $id = 0; if (is_array($exts)) { $exts = implode("|", $exts); } foreach (glob($dirPath . '*') as $v) { $id++; if (is_dir($v) || !$exts || preg_match("/\\.({$exts})/i", $v)) { $list[$id]['name'] = basename($v); $list[$id]['path'] = str_replace("\\", "/", realpath($v)); $list[$id]['type'] = filetype($v); $list[$id]['filemtime'] = filemtime($v); $list[$id]['fileatime'] = fileatime($v); $list[$id]['size'] = is_file($v) ? filesize($v) : self::get_dir_size($v); $list[$id]['iswrite'] = is_writeable($v) ? 1 : 0; $list[$id]['isread'] = is_readable($v) ? 1 : 0; } if ($son) { if (is_dir($v)) { $list = self::tree($v, $exts, $son = 1, $list); } } } return $list; }
/** * 获取文件夹细信息 */ function folder_info($path, $date_formate = false) { if (!$date_formate) { $date_formate = $GLOBALS['L']['time_type']; } $info = array('name' => iconv_app(get_path_this($path)), 'path' => iconv_app(get_path_father($path)), 'type' => 'folder', 'mode' => get_mode($path), 'atime' => date($date_formate, fileatime($path)), 'ctime' => date($date_formate, filectime($path)), 'mtime' => date($date_formate, filemtime($path)), 'is_readable' => intval(is_readable($path)), 'is_writeable' => intval(is_writeable($path))); return $info; }
function testGetFileTime() { $p = PMVC\plug($this->_plug); $f = $p->file(__FILE__); $atime = fileatime($f->realPath()); $time = date('Y/m/d H:i:s', $atime); $this->assertEquals($time, (string) $f->getTime()->atime()); }
function get_info_file($url_file) { $tab_infos['name'] = basename($url_file); $tab_infos['size'] = filesize($url_file); $tab_infos['ctime'] = date("Y-m-d H:i:s", filectime($url_file)); $tab_infos['mtime'] = date("Y-m-d H:i:s", filemtime($url_file)); $tab_infos['atime'] = date("Y-m-d H:i:s", fileatime($url_file)); return $tab_infos; }
function vio_atime($fname) { if (time() - fileatime($fname) - $this->_timelimit > 0) { unlink($fname); return $this->_timelimit; } return false; }
/** * Cleanup old sessions * @link http://php.net/manual/en/sessionhandlerinterface.gc.php * @param int $maxlifetime <p> * Sessions that have not updated for * the last maxlifetime seconds will be removed. * </p> * @return bool <p> * The return value (usually TRUE on success, FALSE on failure). * Note this value is returned internally to PHP for processing. * </p> * @since 5.4.0 */ public function gc($maxlifetime) { $files = glob(Configuration::getInstance()->get("Session/FileHandler/directory") . '/*'); foreach ($files as $file) { if (file_exists($file) and time() - fileatime($file) <= $maxlifetime) { unlink($file); } } return true; }
/** * @inheritdoc * * @param mixed $default The value returned if the key does not exists. Defaults to `null`. */ public function retrieve($key, $default = null) { $this->check_writable(); $pathname = $this->format_pathname($key); $ttl_mark = $this->format_pathname_with_ttl($pathname); if (file_exists($ttl_mark) && fileatime($ttl_mark) < time() || !file_exists($pathname)) { return $default; } return $this->unserialize(file_get_contents($pathname)); }
public function GC() { //尝试进行回收 $files = IO::AllFile($this->path); foreach ($files as $file) { Log::Debug("{$file} =" . date('[Y-m-d H:i:s]', fileatime($file))); if (time() - fileatime($file) > 1440) { unlink($file); } } }
/** * */ protected function _loadMetaData() { clearstatcache(); $this->_format = strtolower(pathinfo($this->_filename, PATHINFO_EXTENSION)); $this->_size = filesize($this->_filename); $this->_modificationTime = filemtime($this->_filename); $this->_accessTime = fileatime($this->_filename); $this->_isExecutable = is_executable($this->_filename); $this->_isReadable = is_readable($this->_filename); $this->_isWritable = is_writable($this->_filename); }
/** * Cleans form states older than two hours */ public static function CleanStaleFormStates() { $arrFileList = self::ListDirectory(__FILE_FORM_STATE_HANDLER_PATH__, '/qformstate_.*/'); if (is_array($arrFileList)) { foreach ($arrFileList as $strFile) { if (fileatime($strFile) < time() - 7200) { unlink($strFile); } } } }
public function testTimestamp() { $data = 'FooFooBarBar'; $id = hash('sha1', $data); $file = Config::get('page') . '/object/' . $id; touch($file); $time = fileatime($file); $object = new Object($data, 'data'); $this->assertEquals($time, fileatime($file)); $this->assertEmpty(file_get_contents($file)); }