View Full Version : reading time from a file
07-14-2012, 11:48 PM
How can i read the time from a file uploaded/created?
i like to include a new hidden field to store into mysql along with the file detail, so later i can sort thru time.
thank you for your time n help in advance
07-15-2012, 12:44 AM
Is the time already written to the file, and if so, in what format? Or do you have to devise a way to write the time to the file too, and also in what format? As for doing what you asked, you fopen the file, place the file pointer at the proper line in the file, and read that line. But if you want more information you'll have to supply more too.
07-15-2012, 01:26 AM
the time you uploaded it or the time the file was originally created on the client ? , if the latter you cant get that.
if the time you uploaded simply add a time field in your database table you can use mysql NOW() function to add the time of the operation
`db_field` = NOW()
07-15-2012, 02:22 AM
thank you both
currently i have a column in a table to show all the uploaded files.
what i need help is to have some php code line, which will loop or display each file's last modified time or server uploaded time.. that way, at the end, i will have 2 columsn to show the filename and date/time to sort.
07-15-2012, 03:57 AM
You could try these, they are untested and I don't know what sort of info they will display.
// get file access/modification times
echo "Last accessed on: " . date("d-m-y", fileatime('myfile.html'));
echo "Last modified on: " . date("d-m-y", filemtime('myfile.html'));
// get file statistics
The uploaded time is easy and would be coded into the upload form to be entered into the database automatically.
07-15-2012, 07:34 PM
thank you Len
it helped me, got it to work manually, when i list the filename..
i currently use this line to pull up the filename uploaded with its href
echo "<a href=\"users". "/" . $username . $viewurl . "/" . $filearray[$index] . "\">" . $filearray[$index] . "</a> ";
I tried implementing in your code, but i keep getting errors with "" syntax error, unexpected T_STRING etc.
Could you please let me know how to implement it correctly
Note: from the code line i posted above, it shows the filename AND its fullpath. but in this case, we only need the fullpath for filemtime or fileatime.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.