本文整理汇总了PHP中SplFileInfo::getMTime方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo::getMTime方法的具体用法?PHP SplFileInfo::getMTime怎么用?PHP SplFileInfo::getMTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFileInfo
的用法示例。
在下文中一共展示了SplFileInfo::getMTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadCachedFile
protected function loadCachedFile()
{
if (!$this->cacheFile->isReadable()) {
return null;
}
if ($this->cacheFile->getMTime() < $this->dataFile->getMTime()) {
return null;
}
$jsonString = file_get_contents($this->cacheFile->getPathname());
if (false === $jsonString) {
throw new InvalidArgumentException("Can not read file content from '{$this->cacheFile->getPathname()}'!");
}
return CiteCollection::loadFromJson($jsonString);
}
示例2: __construct
/**
* @param \SplFileInfo $fileInfo
* @param string $downloadDirUrl
*/
public function __construct(\SplFileInfo $fileInfo, $downloadDirUrl)
{
$this->size = $fileInfo->getSize();
$this->fileName = $fileInfo->getBasename();
$this->lastModified = \DateTime::createFromFormat("U", $fileInfo->getMTime());
$this->url = "{$downloadDirUrl}/" . rawurlencode($this->fileName);
}
示例3: calculate
/**
* Returns file checksum
*
* @param string $file
* @return string
*/
public function calculate($file)
{
$file = new \SplFileInfo($file);
if (!$file->isFile() && !$file->isReadable()) {
throw new \InvalidArgumentException('Invalid argument supplied for checksum calculation, only existing files are allowed');
}
return sprintf('%s:%s', $file->getMTime(), $file->getSize());
}
示例4: isModified
public function isModified($timestamp)
{
$info = new \SplFileInfo($this->file);
$mtime = $info->getMTime();
unset($info);
if ($mtime != $timestamp) {
return true;
}
return false;
}
示例5: isFileChanged
private function isFileChanged(\SplFileInfo $file, &$previously)
{
$name = $file->getFilename();
$mtime = $file->getMTime();
if (isset($previously[$name])) {
$changed = $previously[$name]['mtime'] != $mtime;
} else {
$changed = true;
}
$previously[$name] = array('mtime' => $mtime);
return $changed;
}
示例6: gc
public function gc()
{
$cache_seconds = usu::$cachedays * 24 * 60 * 60;
if (is_readable($this->cachpath)) {
$fileInfo = new SplFileInfo($this->cachpath);
if (time() > $fileInfo->getMTime() + $cache_seconds) {
unlink($this->cachpath);
return true;
}
}
return false;
}
示例7: isFresh
/**
* @return bool
*/
public function isFresh()
{
if (!$this->getFileSystem()->exists($this->getCacheDir() . $this->getFileName())) {
return false;
}
$file = new \SplFileInfo($this->getCacheDir() . $this->getFileName());
$lifetimeEnd = (new \DateTime("@{$file->getMTime()}"))->modify($this->getLifetime());
if ($lifetimeEnd < new \DateTime()) {
return false;
}
return true;
}
示例8: toArray
/**
* @return array
*/
public function toArray()
{
$rows = [];
$currentDir = getcwd() . DIRECTORY_SEPARATOR;
/* @var $reflection ReflectionFile */
foreach ($this->getIterator() as $reflection) {
$row = [];
$file = new \SplFileInfo($reflection->getName());
$row = array("Files" => str_replace($currentDir, "", $file->getPathName()), "Owner" => $file->getOwner(), "Group" => $file->getGroup(), "Permissions" => $file->getPerms(), "Created" => date("d.m.Y h:m:s", $file->getCTime()), "Modified" => date("d.m.Y h:m:s", $file->getMTime()));
$rows[] = $row;
}
return $rows;
}
示例9: get_content
/**
* Retrieve directory content, directories and files
*
* @param Application $app Silex Application
* @param Request $request Request parameters
*
* @return JsonResponse Array of objects
*/
function get_content(Application $app, Request $request)
{
$dirpath = Utils\check_path($app['cakebox.root'], $request->get('path'));
if (!isset($dirpath)) {
$app->abort(400, "Missing parameters");
}
$finder = new Finder();
$finder->followLinks()->depth('< 1')->in("{$app['cakebox.root']}/{$dirpath}")->ignoreVCS(true)->ignoreDotFiles($app['directory.ignoreDotFiles'])->notName($app["directory.ignore"])->sortByType();
$dirContent = [];
foreach ($finder as $file) {
if ($file->isLink()) {
$linkTo = readlink("{$app['cakebox.root']}/{$dirpath}/{$file->getBasename()}");
if (file_exists($linkTo) == false) {
continue;
}
$file = new \SplFileInfo($linkTo);
}
$pathInfo = [];
$pathInfo["name"] = $file->getBasename();
$pathInfo["type"] = $file->getType();
$pathInfo["mtime"] = $file->getMTime();
$pathInfo["size"] = Utils\get_size($file);
$pathInfo["access"] = str_replace('%2F', '/', rawurlencode("{$app['cakebox.access']}/{$dirpath}/{$file->getBasename()}"));
$pathInfo["extraType"] = "";
$ext = strtolower($file->getExtension());
if (in_array($ext, $app["extension.video"])) {
$pathInfo["extraType"] = "video";
} else {
if (in_array($ext, $app["extension.audio"])) {
$pathInfo["extraType"] = "audio";
} else {
if (in_array($ext, $app["extension.image"])) {
$pathInfo["extraType"] = "image";
} else {
if (in_array($ext, $app["extension.archive"])) {
$pathInfo["extraType"] = "archive";
} else {
if (in_array($ext, $app["extension.subtitle"])) {
$pathInfo["extraType"] = "subtitle";
}
}
}
}
}
array_push($dirContent, $pathInfo);
}
return $app->json($dirContent);
}
示例10: get
/**
* Get a stored value
* @param string $group
* @param string $name
* @param mixed $default
* @return mixed
*/
public function get($group, $name, $default = NULL)
{
// explode on separator
$parts = explode($this->params['separator'], $name);
// add group to front
array_unshift($parts, $group);
// last part is filename
$filename = array_pop($parts) . '.cache';
// get directory
$directory = $this->dir->getRealPath() . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parts) . DIRECTORY_SEPARATOR;
// get file
$file = new \SplFileInfo($directory . $filename);
if (!$file->isFile()) {
// file doesnt exist: return default
return $default;
} else {
// get time created
$created = $file->getMTime();
// get data handle
$data = $file->openFile();
// lifetime is the first line
$lifetime = $data->fgets();
if ($data->eof()) {
// end of file: cache is corrupted: delete it and return default
unlink($file->getRealPath());
return $default;
}
// read data lines
$cache = '';
while ($data->eof() === FALSE) {
$cache .= $data->fgets();
}
if ($created + (int) $lifetime < time()) {
// Expired: delete the file & return default
unlink($file->getRealPath());
return $default;
} else {
try {
$unserialized = unserialize($cache);
} catch (Exception $e) {
// Failed to unserialize: delete file and return default
unlink($file->getRealPath());
$unserialized = $default;
}
return $unserialized;
}
}
}
示例11: __construct
public function __construct($path, $source = null)
{
if (!file_exists($path)) {
throw new \Exception("{$path} file Not Found");
}
$this->time_create = time();
$this->name = session_id() . '_' . md5($path);
$file = new \SplFileInfo($path);
$this->file_name_no_extension = str_replace('.' . $file->getExtension(), '', $file->getFilename());
$this->type = $file->getExtension();
$this->file_name = $file->getFilename();
$this->path = $path;
$this->dir = dirname($path);
$this->modefy = $file->getMTime();
$this->source = $source;
}
示例12: addFile
/**
* Add a file to the list.
*
* @param string $file The file
* @param \SplFileInfo $fileInfo
* @return FileList
*/
public function addFile($file, $fileInfo)
{
if (!$fileInfo instanceof SplFileInfo) {
$fileInfo = new SplFileInfo($fileInfo);
}
$this->files[$file] = $fileInfo;
try {
$mTime = $fileInfo->getMTime();
} catch (Exception $e) {
$mTime = 0;
}
if ($mTime > $this->maxMTime) {
$this->maxMTime = $mTime;
}
return $this;
}
示例13: createFileFromFileInfo
/**
* create file from SplFileInfo
*
* @param SplFileInfo $file
* @return Post
*/
private function createFileFromFileInfo(\SplFileInfo $file)
{
$post = new Post($this->getFilter());
$post->setText(file_get_contents((string) $file));
$post->setIdentifier(str_replace('.markdown', '', $file->getFilename()));
$post->setCreated($file->getCTime());
$post->setModified($file->getMTime());
$matches = array();
$found = preg_match('/#.*/', $post->getText(), $matches);
if ($found === false) {
$title = $file->getFilename();
} else {
$title = ltrim(array_shift($matches), '#');
}
$post->setTitle($title);
//parse title out of body text
return $post;
}
示例14: checkFile
public function checkFile(\SplFileInfo $file)
{
$path = $file->getPathname();
clearstatcache(true, $path);
$mtime = $file->getMTime();
$dispatch = false;
if (isset($this->files[$path])) {
$previous = $this->files[$path];
if ($mtime > $previous) {
$dispatch = true;
$this->modify($file);
}
}
if ($dispatch) {
$this->all($file);
}
$this->files[$path] = $mtime;
}
示例15: connect
public function connect(Application $app)
{
global $beforeTokenCheker;
$controllers = $app['controllers_factory'];
$self = $this;
// ToDo: Add token check
$controllers->get('/filedownloader', function (Request $request) use($app, $self) {
$fileID = $request->get('file');
$filePath = __DIR__ . '/../../../' . FileController::$fileDirName . "/" . basename($fileID);
$app['logger']->addDebug($filePath);
if (file_exists($filePath)) {
$response = new Response();
$lastModified = new \DateTime();
$file = new \SplFileInfo($filePath);
$lastModified = new \DateTime();
$lastModified->setTimestamp($file->getMTime());
$response->setLastModified($lastModified);
if ($response->isNotModified($request)) {
$response->prepare($request)->send();
return $response;
}
$response = $app->sendFile($filePath);
$currentDate = new \DateTime(null, new \DateTimeZone('UTC'));
$response->setDate($currentDate)->prepare($request)->send();
return $response;
} else {
return $self->returnErrorResponse("file doesn't exists.");
}
});
//})->before($app['beforeTokenChecker']);
// ToDo: Add token check
$controllers->post('/fileuploader', function (Request $request) use($app, $self) {
$file = $request->files->get(FileController::$paramName);
$fineName = \Spika\Utils::randString(20, 20) . time();
if (!is_writable(__DIR__ . '/../../../' . FileController::$fileDirName)) {
return $self->returnErrorResponse(FileController::$fileDirName . " dir is not writable.");
}
$file->move(__DIR__ . '/../../../' . FileController::$fileDirName, $fineName);
return $fineName;
})->before($app['beforeApiGeneral']);
//})->before($app['beforeTokenChecker']);
return $controllers;
}