Thursday, 27 April 2017

Change modified time of file using PHP Touch()

<?php

$file = 'touch.php';

// One you use filemtime it stores, You will need to clear cache before using it again.
echo '<br/>';
echo "$file was last modified: " . date ("F d Y H:i:s.", filemtime($file));

clearstatcache();
 
// This is the touch time, we'll set it to one hour in the past.
$time = time() - ( 3600 * 24 ); // 1 day before

// Touch the file
if (!touch($file, $time)) {
    echo 'Whoops, something went wrong...';
} else {
    echo "<br/> $file was last modified: " . date ("F d Y H:i:s.", filemtime($file));
}

?>

No comments:

Post a Comment