Forum Moderators: coopster

Message Too Old, No Replies

Updated script

         

Champak

9:14 pm on Feb 2, 2007 (gmt 0)

10+ Year Member



Could someone help me fix this code to give the date of file modified/upload.

I've got this, but it wont give me the right date, what am I doing wrong:
<?
$last_modified = filemtime("gp_submissions2.pdf");
print("");
print(date("m/j/y h:i", $last_modified));
?>

Thanks.

[edited by: Champak at 9:40 pm (utc) on Feb. 2, 2007]

eelixduppy

9:43 pm on Feb 2, 2007 (gmt 0)



You can take a look at stat [us2.php.net] as it gives much information about the specified file. If this doesn't work, then you are either going to have to log the time as a timestamp in a database or flat-file, or use an outside source other than php.

In either case, I wish you luck! :)

[edit]
Looks like you changed your whole post ;)

Well, what you have works fine, however it gives the time that the file was last modified. You, however, want the time of upload. I'm afraid you are going to have to log a timestamp to be 100% sure, unless you know that the files will never be modified after the upload date, in which case your solution should work.
[/edit]

whoisgregg

10:12 pm on Feb 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could include a "creation timestamp" in the filename when it's created... Although I rather prefer the idea of storing that information in a database. You're probably storing information in the database already, if not then now is the time to start. ;)

filename.20070202.jpg

Champak

2:09 am on Feb 3, 2007 (gmt 0)

10+ Year Member



Sorry, I should have been a little clearer. I know the code works within it self, I shortened it for the post not realizing that shortening it is actually making it work now. It was not working because I had the file to check in a subdirectory instead of in the root. So what the code actually looked like was:

<?
$last_modified = filemtime("/path/downloads/gp_submissions2.pdf");
print("");
print(date("m/j/y h:i", $last_modified));
?>

So for anyone else who may have this problem because the file they want to check is in a subdirectory, to solve it make the path from the from the root like: /home/whatever/public_html/path/file.pdf

I actually want the modified date, not the upload date, so it is giving me what I expect.

[edited by: Champak at 2:10 am (utc) on Feb. 3, 2007]