简体   繁体   English

PHP filemtime返回当前日期

[英]PHP filemtime returns current date

I want to get modified date of the file that is uploaded but it returns current time (which I guess it's because filemtime returns modified date of temp file so long story short how can I get the true modified date? 我想获得上传文件的修改日期,但它返回当前时间(我想这是因为filemtime返回临时文件的修改日期,所以长篇故事如何获得真正的修改日期?

here is my code it's (laravel framework) 这是我的代码(laravel框架)

$file = $request->file;
dd(filemtime($file));

Well, you could use Storage::lastModified($path) to get modified date of the file, and don't forget add use Illuminate\\Support\\Facades\\Storage; 那么,您可以使用Storage::lastModified($path)来获取文件的修改日期,并且不要忘记添加use Illuminate\\Support\\Facades\\Storage; , hope it will help you guys. ,希望它会帮助你们。

<?php
// outputs e.g.  somefile.txt was last modified: December 29 2002 22:16:23.

$filename = 'somefile.txt';
if (file_exists($filename)) {
    echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
}
?>

The above code worked for, try it from your end, let me know, if any errors. 上面的代码工作,从你的最终尝试,让我知道,如果有任何错误。

If you want to use protogenous php, you could use filemtime(storage_path("app/yourPath").$file) to get last modified date of the file. 如果你想使用protogenous php,你可以使用filemtime(storage_path(“app / yourPath”)。$ file)来获取文件的最后修改日期。 Because the storage_path() could get the real path that restore your file. 因为storage_path()可以获得恢复文件的真实路径。 Hope it will help you. 希望它会对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM