public function lastModified($path) { $view = $this->view($path); $path = $view->getPath(); $timestamp = \File::lastModified($path); $carbon = Carbon::createFromTimestamp($timestamp); return $carbon; }
/** * Check last backup time * * Checks the modification time of files in authenticated user archive folder and if one of them is less than * 5 minutes ago. * * @param User $user * * @return bool False if last backup was made less than 5 minutes ago, true otherwise */ public static function checkLastBackupTime(User $user) { $zipFiles = File::files(storage_path() . '/backups/' . $user->getId() . '/zip/'); foreach ($zipFiles as $zipFile) { $timeOfBackup = File::lastModified($zipFile); if ($timeOfBackup > strtotime('-5 minutes')) { return false; } } return true; }
/** * Returns a script tag with the compiled file if everything went well, * or else it will return script tags with the uncompiled javascript files * * @param mixed $files a string or an array of files * @return string Script-tags */ function javascript_compiled($files) { $gcc = \App::make('gcc'); $gcc->reset(); $gcc->setFiles($files); if (in_array(\App::environment(), \Config::get('laravel-gcc::env')) && $gcc->compile()) { return \HTML::script($gcc->getCompiledJsURL()); } $dir = $gcc->getJsDir(); $output = ""; foreach ($gcc->getFiles() as $filename => $path) { $output .= \HTML::script($dir . '/' . $filename . '?' . \File::lastModified($path)); } return $output; }
/** * Get a list of deployments * * @return remote.server.deploy.Deployable[] */ public function scanDeployments() { clearstatcache(); $this->changed = FALSE; while ($entry = $this->folder->getEntry()) { if (!preg_match($this->pattern, $entry)) { continue; } $f = new File($this->folder->getURI() . $entry); if (isset($this->files[$entry]) && $f->lastModified() <= $this->files[$entry]) { // File already deployed continue; } $this->changed = TRUE; $ear = new Archive(new File($this->folder->getURI() . $entry)); try { $ear->open(ARCHIVE_READ) && ($meta = $ear->extract('META-INF/bean.properties')); } catch (Throwable $e) { $this->deployments[$entry] = new IncompleteDeployment($entry, $e); continue; } $prop = Properties::fromString($meta); $beanclass = $prop->readString('bean', 'class'); if (!$beanclass) { $this->deployments[$entry] = new IncompleteDeployment($entry, new FormatException('bean.class property missing!')); continue; } $d = new Deployment($entry); $d->setClassLoader(new ArchiveClassLoader($ear)); $d->setImplementation($beanclass); $d->setInterface($prop->readString('bean', 'remote')); $d->setDirectoryName($prop->readString('bean', 'lookup')); $this->deployments[$entry] = $d; $this->files[$entry] = time(); delete($f); } // Check existing deployments foreach (array_keys($this->deployments) as $entry) { $f = new File($this->folder->getURI() . $entry); if (!$f->exists()) { unset($this->deployments[$entry], $this->files[$entry]); $this->changed = TRUE; } delete($f); } $this->folder->close(); return $this->changed; }
function ServletContext($web_xml_file) { $web_xml_file = new File($web_xml_file); if (File::validClass($web_xml_file) && $web_xml_file->exists()) { $this->file =& $web_xml_file; $cache_file = new File($web_xml_file->getFilePath() . 'cached'); $valid_cache = FALSE; if ($cache_file->exists() && $web_xml_file->lastModified() == $cache_file->lastModified()) { $this->config = @unserialize(FileReader::readFileContent($cache_file)); if (ServletContext::validClass($this->config)) { $valid_cache = TRUE; } } if (!$valid_cache) { $this->config =& ServletXMLConfigReader::readXMLConfig(new FileReader($web_xml_file)); FileWriter::writeToFile($cache_file, serialize($this->config), $web_xml_file->lastModified()); } } if (isset($this->config)) { $this->initServletContext(); } }
/** * Download remote file to local file. * * @throws * @param string $remote_file * @param string $local_file */ public function get($remote_file, $local_file) { $lfile = File::exists($local_file); if ($lfile && $this->hasCache($remote_file, File::md5($local_file))) { $this->_log($remote_file . ' exists'); return; } $this->_log("download {$remote_file} as {$local_file}"); $ret = @ftp_nb_get($this->ftp, $local_file, $remote_file, FTP_BINARY); while ($ret === FTP_MOREDATA) { $ret = @ftp_nb_continue($this->ftp); } if ($ret !== FTP_FINISHED) { throw new Exception('FTP download failed', "local_file={$local_file} remote_file={$remote_file}"); } $this->cache[$remote_file] = [File::md5($local_file), File::size($local_file), File::lastModified($local_file)]; }
/** * Get a file * * @param string filename * @return org.webdav.WebdavObject * @throws lang.ElementNotFoundException * @throws org.webdav.OperationNotAllowedException */ public function get($filename, $token = NULL) { $this->c->debug('FILENAME', $filename); $this->c->debug('TOKEN', $token); $filename = $this->_normalizePath($filename); // check for lock $lockinfo = $this->getLockInfo($filename); if ($lockinfo and $lockinfo['type'] == 'exclusive' and 'opaquelocktoken:' . $lockinfo['token'] != $token) { throw new IllegalArgumentException($filename . ' is locked exclusive'); } if (is_dir($this->base . $filename)) { $this->c->debug(get_class($this), '::GET Dir', $filename); $f = new Folder($this->base . $filename); if (!$f->exists()) { throw new ElementNotFoundException($filename . ' not found'); } while ($maxdepth >= 0 && ($entry = $f->getEntry())) { $isdir = is_dir($this->base . $filename . '/' . $entry); $atime = date('H:i:s d.m.y', fileatime($this->base . $filename . '/' . $entry)); if ($isdir) { $flist[0][$entry] .= sprintf(' <tr> <td><a href="%s/">%s</a></td> <td><DIR></td> <td>%s</td> <td> </td> </tr> ', rawurlencode($entry), $entry, $atime); } else { $flist[1][$entry] .= sprintf(' <tr> <td><a href="%s">%s</a></td> <td> </td> <td>%s</td> <td>%s Bytes</td> </tr> ', rawurlencode($entry), $entry, $atime, filesize($this->base . $filename . '/' . $entry)); } } asort($flist[0]); $html = '<table cellpadding=3>' . (strlen($filename) > 2 ? '<tr><td><a href="../">..</a></td><td><DIR></tr>' : '') . implode('', $flist[0]); asort($flist[1]); $flist = $html . implode('', $flist[1]) . '</table>'; $o = new WebdavObject($f->uri, NULL, strlen($flist), 'text/html', new Date(filectime($f->uri)), new Date(filemtime($f->uri))); $o->setData($flist); $f->close(); return $o; } $this->c->debug(get_class($this), '::GET filename', $filename); $this->c->debug(get_class($this), '::GET base', $this->base); // Open file and read contents // contentype if (!file_exists($this->base . $filename)) { throw new ElementNotFoundException($filename . ' not found'); } $f = new File($this->base . $filename); $contentType = ''; $this->c->debug(get_class($this), '::get ', $this->base . filename); $eProps = $this->propStorage->getProperties($f->uri); if (!empty($eProps['getcontenttype'])) { $contentType = $eProps['getcontenttype'][0]; } if (empty($contentType)) { $contentType = MimeType::getByFilename($f->uri, 'text/plain'); } $o = new WebdavObject($f->uri, NULL, $f->size(), $contentType, new Date($f->createdAt()), new Date($f->lastModified())); try { $f->open(FILE_MODE_READ); $o->setData($f->read($f->size())); $f->close(); } catch (FileFoundException $e) { throw new ElementNotFoundException($filename . ' not found'); } $this->c->debug('OBJ', $o->properties); return $o; }
private function displayImage(File $oImageFile) { $oHeader = new HTTPHeader(); if (!$oHeader->isModifiedSince($oImageFile->lastModified())) { $oHeader->setResponseCode(304); } else { $oHeader->setResponse('Content-Type', 'image/png'); $oImageFile->readStdOut(); } }
<?php App::before(function ($request) { Route::group(['prefix' => Config::get('cms.backendUri', 'backend')], function () { Route::any('indikator/qedit/content', function () { if (File::exists('themes/' . get('path'))) { $content = File::get('themes/' . get('path')); if (substr_count(get('path'), '/content/') == 0) { $content = substr($content, strrpos($content, '==') + 2); } return trim($content); } else { return ''; } }); Route::any('indikator/qedit/date', function () { if (File::exists('themes/' . get('path'))) { return date('Y-m-d G:i', File::lastModified('themes/' . get('path'))); } else { return ''; } }); }); });
/** * Scan $this->path_absolute and set md5, size and last_modified properties. * If with and height property exists retrieve image dimensions. */ protected function scanFile() { $this->md5 = File::md5($this->path_absolute); $this->size = File::size($this->path_absolute); $this->last_modified = File::lastModified($this->path_absolute); if (property_exists($this, 'width') && property_exists($this, 'height')) { $ii = File::imageInfo($this->path_absolute); $this->width = intval($ii['width']); $this->height = intval($ii['height']); } }
out::prntln("Last index of 'o': " . ((!$hello->lastIndexOf("o")) ? 'false' : $hello->lastIndexOf("o"))); // ----------------------------------------------------- // // New Section out::prntln(); // ----------------------------------------------------- // // Initialize a File $file = new File("index.php"); // Get the name out::prntln("Filename? " . $file->getName()); // Is it a file? out::prntln("File? " . (($file->isFile()) ? 'true' : 'false')); // Check validation. out::prntln("Does it exist? " . (($file->exists()) ? 'true' : 'false')); // Attempt creation out::prntln("Creation? " . (($file->createNewFile()) ? 'true' : 'false')); // Size? out::prntln("Size: " . $file->length()); // Last modified? out::prntln("Last modified: " . $file->lastModified()); // ----------------------------------------------------- //
/** * * @param string $filename Of build file * @return \Response Contents if first request, else cache header */ public static function getCompiledFile($filename) { $path = static::storagePath($filename . '.js'); if (!\File::exists($path)) { return \App::abort(404); } $headerMod = \Request::header('If-Modified-Since'); $headers = array('Content-Type' => 'text/javascript', 'Last-Modified' => gmdate('D, d M Y H:i:s \\G\\M\\T', \File::lastModified($path))); $headerGzip = \Request::header('Accept-Encoding'); if ($headerGzip && str_contains($headerGzip, 'gzip') && function_exists('gzencode')) { $headers['Content-Encoding'] = 'gzip'; } if ($headerMod && strtotime($headerMod) == \File::lastModified($path)) { return \Response::make(null, 304, $headers); } else { $contents = \File::get($path); if ($headerGzip && str_contains($headerGzip, 'gzip') && function_exists('gzencode')) { $contents = gzencode($contents, 9); } $headers = array_merge($headers, array('Cache-Control' => 'max-age=' . 60 * 60 * 24 * 7, 'Expires' => gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 60 * 60 * 24 * 7), 'Content-Length' => strlen($contents))); return \Response::make($contents, 200, $headers); } }