mohammad
mohammad

Reputation: 47

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?

here is my code it's (laravel framework)

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

Upvotes: 1

Views: 3741

Answers (3)

Martin
Martin

Reputation: 171

If you want to use protogenous php, you could use filemtime(storage_path("app/yourPath").$file) to get last modified date of the file. Because the storage_path() could get the real path that restore your file. Hope it will help you.

Upvotes: 0

Martin
Martin

Reputation: 171

Well, you could use Storage::lastModified($path) to get modified date of the file, and don't forget add use Illuminate\Support\Facades\Storage;, hope it will help you guys.

Upvotes: 5

user6889084
user6889084

Reputation:

<?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.

Upvotes: 0

Related Questions