PHP Check if a file was modified more than 1 hour ago

Posted on November 3, 2018 at 5:44 pm

Simple PHP snippet to check if a file was last modified more than 1 hour ago:

if(time() - filemtime("/path/to/file") >= 1 * 3600) { 
    echo "File was modified more than 1 hour ago"; 
}

Check if a file was mofified more than 2 hours ago:

if(time() - filemtime("/path/to/file") >= 2 * 3600) { 
    echo "File was modified more than 2 hours ago"; 
}

Check if a file was mofified more than 30 minutes ago:

if(time() - filemtime("/path/to/file") >= 30 * 60) { 
    echo "File was modified more than 30 minutes ago"; 
}

Check if a file was mofified more than 15 minutes ago:

if(time() - filemtime("/path/to/file") >= 15 * 60) { 
    echo "File was modified more than 30 minutes ago"; 
}

Receive updates via email

Other Posts

Updated Posts