我在那里,我正在编写一个单元测试,断言文件没有被修改.测试代码执行时间不到一秒,因此我想知道是否可以以毫秒为单位检索文件修改时间.filemtime()函数以秒为单位返回UNIX时间戳.
我目前的解决方案是使用sleep(1)函数,这将确保在检查它是否被修改之前经过1秒.我不喜欢这种解决方案,因为它大大减慢了测试速度.
我无法通过get_file_contents()声明内容相等,因为可以重写的数据是相同的.
我猜这不可能,是吗?
当使用Paramiko从一台服务器到另一台服务器的SFTP文件时,是否有一种方法可以保留时间戳,类似于-pLinux中的参数?
原始档案:
jim@vm3634:~$ ls -la
-rwxrwx--- 1 jim admin 2214 Mar 30 17:33 compcip.asc
Run Code Online (Sandbox Code Playgroud)
上传的文件:
sftp> ls -la
-rwxrwx--- 1 no-user no-group 2214 Mar 30 18:49 compcip.asc
Run Code Online (Sandbox Code Playgroud)
上传的文件需要与原始文件具有相同的时间戳.
我有一个包含4个文件的文件夹,我想拉最近一次的修改时间(可能并不总是相同).有没有一个好方法呢?
试试跑步
<?php
echo filemtime("test.txt")."\n";
sleep(4);
file_put_contents("test.txt", "test");
echo filemtime("test.txt")."\n";
?>
Run Code Online (Sandbox Code Playgroud)
对我来说打印的命令行:
1343490984
1343490984
Run Code Online (Sandbox Code Playgroud)
那可能不对,可以吗?
在Ubuntu 12.04上,打开一个新的文本文件并编写:
#include <stdlib.h>
int main()
{
abort();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
现在运行:
g++ yourfile.cpp
Run Code Online (Sandbox Code Playgroud)
然后运行可执行文件,该文件将进行核心转储:
./a.out
Run Code Online (Sandbox Code Playgroud)
现在检查文件的mtime:
-rw-r----- 1 xxxxx xxxxx 228K 2012-10-01 19:20:20.752136399 -0500 core
Run Code Online (Sandbox Code Playgroud)
现在再次运行可执行文件:
./a.out
Run Code Online (Sandbox Code Playgroud)
现在再次检查mtime:
-rw-r----- 1 xxxxx xxxxx 228K 2012-10-01 19:20:20.752136399 -0500 core
Run Code Online (Sandbox Code Playgroud)
一样的!为什么新的核心不会覆盖旧的核心?重建时,这会导致gdb抱怨内核比可执行文件旧。
为了确保这不是许可问题,我在/ tmp的新目录中尝试了此操作并在其中运行chmod -R 777 **/*。运行两次可执行文件仍然不会产生新的内核O_o。此外,ulimit -c报告有800000000,对于这样大小的内核来说绰绰有余。
我还尝试过使用干净的bash env - bash --noprofile --norc并仍然运行二进制文件不会更新内核的mtime,除非我先删除它。
我做了一些不成功的尝试.我希望通过当前文件(即当前正在查看的文件)获取上次修改的文件时间.以下代码适用于employer.es.php文件,但我在其他文件中重复使用它,除非我不断更改文件名.
<?php
// make var from file name
$last_modified = filemtime("employer.es.php");
// print date
echo "Information last modified on " . date("m/d/Y", $last_modified);
?>
Run Code Online (Sandbox Code Playgroud)
因此,我不想在每个文件中键入文件名,而是希望它使用当前文件.希望我有意义:/谢谢!
我正在尝试使用fwrite将文件写入文件之前和之后获取文件的最后修改时间。但是,由于某种原因,我得到相同的值。
<?php
$i = filemtime('log.txt');
echo gmdate("h:i:s", $i);
echo "<br/>";
$e=fopen('log.txt', 'w');
fwrite($e, "well well well");
$j = filemtime('log.txt');
echo gmdate("h:i:s", $j);
?>
Run Code Online (Sandbox Code Playgroud)
现在,在运行此脚本大约一分钟之前,我使用文本编辑器修改了“ log.txt”。所以我应该得到大约40-60秒的时差。如果有人指出这里发生了什么,那将是非常感谢。谢谢。
我正在尝试使用上次修改某些文件的日期和时间filemtime.不幸的是,这对我的所有文件都失败了.我尝试过使用完整的完整路径(例如www.mysite.com/images/file.png).我尝试过只使用扩展名(例如/images/file.png),还只使用文件名本身(file.png).什么都行不通.如何传递路径引用以便它可以找到我的文件?谢谢!
<br />n<b>Warning</b>: filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for www.mysite.com/images/hills.png in <b>D:\Hosting\11347607\html\mobile\updateImages.php</b> on line <b>20</b><br
Run Code Online (Sandbox Code Playgroud)
这是php脚本:
<?php
include '../scripts/connection.php';
//get information on this location from the database
$sql = "SELECT * FROM types";
$result = mysql_query($sql);
$array = array();
while ($row = mysql_fetch_array($result)) {
$path = $row['path'] . $row['picture_url'];
$last_mod = filemtime($path);
$this_file = array(
'filename' => $row['picture_url'],
'last_mod' => $last_mod
);
$array[$row['type']] = $this_file;
}
echo json_encode(array('result'=>'success', 'message'=>$array));
?>
Run Code Online (Sandbox Code Playgroud) 我正在使用此脚本查看子文件夹的所有子文件夹和文件
function readfolder($dir)
{
global $tfile,$tdir;$i=0;$j=0;$myfiles;
$myfiles[][] = array();
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file=readdir($dh)) !== false) {
if (!is_dir($dir."\\".$file))
{
$tfile[$i]=$file;
$i++;
echo $dir."\\".$file." <b>File</b><br>";
}
else {
if (($file != ".") && ($file != "..")) {
$tdir[$j]=$file;
echo $dir."\\".$file." <b>Directory</b><br>";
readfolder($dir."\\".$file);
$j++;
}
}
}
closedir($dh);
}
}
}
readfolder(".");
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我如何使用filemtime函数(或其他),以便我可以按修改日期对子翻牌和文件进行排序?
我正在尝试确定将图像的最后修改日期存储在MySQL数据库中还是使用PHP函数filemtime更好。
就我而言,所有网站信息都存储在数据库(cms)中,因此总会有一个查询来提取图像路径,等等。问题是出于缓存的目的,我需要让HTML输出如下所示<img src="/img/photo.jpg?v20190613" />。根据我在php.net网站上阅读的内容,此功能已被缓存。那么,它会使用较少的资源向存储上次更新时间戳的数据库表中添加字段还是每次使用此功能吗?两种方式都有优势吗?我正在寻找可以提供最佳性能的产品。