How to find original modification time of the uploaded file

When a file is uploaded  filemtime($_FILES['file']['tmp_name']) gives me the time of  the upload (!)

How can find the find original modification time of the uploaded file?
Thank you
LVL 1
myyisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
You probably cannot find this from information on the server.  The file was modified (or stored, created, etc.) before it was uploaded.  The file upload process does not communicate the file history information See $_FILES to learn what information is sent along with the uploaded file.

For those of us who care about this sort of thing, there is version control.  The most popular tool is Git.  You will get a durable record of the date/time of any "commit" to the repository.
0
Vimal DMSenior Software EngineerCommented:
Hi,

1. The same php function can be used to find out the last modification time of a file. Below is the example for it,

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

Open in new window



2. Use filectime. For Windows it will return the creation time, and for Unix the change time which is the best you can get because on Unix there is no creation time (in most filesystems).
0
Ray PaseurCommented:
The same php function can be used to find out the last modification time of a file.
But only if the modification took place on the server.  Here are some scenarios:

File "X" modified two hours ago on the client machine, then uploaded to the server.  Server thinks the file was modified at the time of upload.

File "Y" modified on the client, then modified again.  Never uploaded.  Server thinks the file does not exist.

File "X" has not been modified for weeks, but gets uploaded and overwritten.  The server thinks the file is newly modified.  The contents might be an exact match between server and client, but the dates will not match at all.

These kinds of problems arise because the client and server are two different machines with two different file systems.  This is exactly the sort of problem that is mitigated by a distributed version control system like Git.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
myyisAuthor Commented:
Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.