0

I am currently doing a project on website programming with PHP and mySQL. In general the project allows users to upload their files to the server and perform searches later according to the "file creation date". I use double quotation here since I want to extract the date when the file was created from nothing (not the file modified date).

I have been looking at a lot of programming forums and reference websites while most of them just introduced the use of filemtime() and filectime(). I have tried both of them and they only returned the "file modified time" (the time when the files were uploaded to the server by me in this development stage).

Knowing the actual file creation time is very important to me because I will use it to perform timeline search later as a requirement of the project. I have got stuck here. Really appreciate any kind help and suggestions.

I am using "xampp" for the web and database servers (the app has the configuration by default) and HTTP+PHP for the front end.

NiC
  • 55
  • 4
  • AFAIK this is impossible. Files, at least in POSIX, don't have an "actual creation time" – jrswgtr Feb 23 '20 at 10:00
  • 2
    With filectime Windows 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). See here https://stackoverflow.com/questions/4401320/php-how-can-i-get-file-creation-date this question already has an answer here. –  Feb 23 '20 at 10:03
  • 1
    Does this answer your question? [PHP: how can I get file creation date?](https://stackoverflow.com/questions/4401320/php-how-can-i-get-file-creation-date) – jrswgtr Feb 23 '20 at 10:09
  • Thank you guys for quick response. Yes the point you have mentioned is what I see in many forums and references. Actually the current work is related to my final year project at my uni. So I may have to review the project requirements or think of other solutions with my supervisor. Many thanks again! – NiC Feb 23 '20 at 10:17
  • The most obvious place to track this kind of info is a database. I presume that's what your supervisor had in mind. – Álvaro González Feb 23 '20 at 18:31

1 Answers1

0

When a user uploads a file in a web browser, what actually happens is that three pieces of information are added to the form submission data:

  • A filename (which a browser will base on the name it had on the user's system)
  • A file type (which will be the browser's best guess, usually just based on the filename)
  • The binary contents of the file

Even if both the user's computer and your server have somewhere to record the creation date of the file, this won't be transmitted with the upload.

There's also something very important thing to bear in mind when building any web-based system: you only have the information the user gives you, and that information could be deliberately or accidentally wrong. If there was a timestamp, it might be wrong because the user's clock is wrong; or it might have been sent by a piece of software that let the user manually set it.

IMSoP
  • 89,526
  • 13
  • 117
  • 169
  • Great inspiration! Perhaps I can ask the users to input the timestamp manually during file upload (so it will be their responsibility to ensure the correctness of the "file creation date"), instead of extracting it directly by the server (which seems impossible anyway). Thanks for your reminder! – NiC Feb 23 '20 at 20:42