Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    Feb 2007
    Location
    London
    Posts
    225
    Thanks
    16
    Thanked 2 Times in 2 Posts

    which path for filemtime to check whole directory?

    Hi,

    I'm using this code to display the last time any page of my site was updated:

    PHP Code:
    putenv("TZ=America/Los_Angeles");
    echo 
    "Site last updated: ".date("dS F Y h:i A"filemtime("/path/to/directory/."))." (PST)."
    ...but I'm not sure what to change the /path/to/directory/ to...

    Is it the path as I see it in my FTP - that doesn't seem to work?
    What does leaving a mere dot there mean?

    Does
    PHP Code:
    filemtime("."
    mean 'everything in the current directory'?

    Thanks

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    If it's in the current directory, just use the filename eg: 'somefile.txt'

  • #3
    Regular Coder
    Join Date
    Feb 2007
    Location
    London
    Posts
    225
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Thanks, but perhaps I didn't explain clearly...

    What I mean is that I want to check when ANY file on the whole site was last edited/updated/uploaded.

  • #4
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Ah. Well filemtime() will check a single file. To use it the way you want, you'll have to loop through each of the files in the directory.

    If you wanted to only check a subset of the files in the directory, you could populate an array with the filenames and loop through that.

  • #5
    Regular Coder
    Join Date
    Feb 2007
    Location
    London
    Posts
    225
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Erm, I'm confused... While I'm sure you're right, it seems that the following quote contradicts you. (This is taken from: http://de3.php.net/function.filemtime )

    To get the last modification time of a directory, you can use this:

    PHP Code:
    $getLastModDir filemtime("/path/to/directory/."); 
    Take note on the last dot which is needed to see the directory as a file and to actually get a last modification date of it.

    This comes in handy when you want just one 'last updated' message on the frontpage of your website and still taking all files of your website into account.
    Am I missing something?
    Thanks a lot. :-)

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    To show the last modified date of the file that code is on you can use $_SERVER['SCRIPT_FILENAME'];
    which will show use the script filename that the echo is running on.

    While this information may or may not be what you need it might be useful to someone.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Quote Originally Posted by cfructose View Post
    Am I missing something?
    Thanks a lot. :-)
    Hmm. Wasn't aware that would work (obviously I've never tried it).

    In that case, I'd try:
    PHP Code:
    filemtime("/."

  • #8
    Regular Coder
    Join Date
    Feb 2007
    Location
    London
    Posts
    225
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Thanks _Aerospace_Eng_ ... useful for some other occasion! :-)

    PappaJohn - I tried using /. but the date then shown is certainly much earlier than the last site update.

    Of course, the guy who posted the quote I gave in last post may just be wrong(?)

    OK, I'm trying to understand how to indicate paths: what does the full stop mean? And does a / with nothing before it indicate the root directory?

    Regardless, to return to my problem, I'm simply looking for a way to print a "Site last updated on..." message in the footer of the site that will automatically detect the last time I uploaded any new/edited file.
    Is the only way really to loop round an array of every file, checking each one's timestamp?

    Thanks

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    This should work
    PHP Code:
    putenv("TZ=America/Los_Angeles");
    echo 
    "Site last updated: ".date("dS F Y h:i A"filemtime($_SERVER['DOCUMENT_ROOT']."/."))." (PST)."
    What the $_SERVER['DOCUMENT_ROOT'] should return is something like this
    Code:
    /home/username/public_html
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #10
    Regular Coder
    Join Date
    Feb 2007
    Location
    London
    Posts
    225
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Almost there... Thanks a lot!

    It successfully updates the date and time for any edited and re-uploaded files in the root directory.

    The final step (I'm hoping this is just a small alteration neede?), is for it to recognise all subfolders too.

    To what should I change:

    PHP Code:
    filemtime($_SERVER['DOCUMENT_ROOT']."/."
    My experiments are all failing! :-)

  • #11
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    What if you did just this?
    PHP Code:
    filemtime($_SERVER['DOCUMENT_ROOT'].'/'
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #12
    Regular Coder
    Join Date
    Feb 2007
    Location
    London
    Posts
    225
    Thanks
    16
    Thanked 2 Times in 2 Posts
    No, that's still only reflecting the last change to a file in the root directory, but not in all subfolders.

    I ask again: I'm trying to understand how to indicate paths: what does the full stop mean? And does a / with nothing before it indicate the root directory?

    I can't seem to find anything out about this, as I'm not sure what to Google for the info. "path syntax?" I'm guessing in the dark without that knowledge...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •