Created
May 16, 2013 12:32
-
-
Save rajvanshipradeep15/5591392 to your computer and use it in GitHub Desktop.
php: delete file if exists more than 3 hrs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Delete file if it exists for more than 3 hrs | |
$path = $_SERVER['DOCUMENT_ROOT']."/delete_test_files"; | |
if ($handle = opendir($path)) { | |
while (false !== ($entry = readdir($handle))) { | |
if ($entry != "." && $entry != ".." && preg_match('/.*.ps/i', $entry)) { | |
$last_modified = filemtime($path .'/' . $entry); | |
$last_modified_str = date("Y-m-d H:i:s", $last_modified); | |
$from_time = strtotime($last_modified_str); | |
$to_time = strtotime(date('Y-m-d H:i:s')); | |
$time_diff = ((round(abs($to_time - $from_time)) / 60))/60; | |
echo $time_diff; | |
if ($time_diff >= 3) { | |
unlink($path . '/' . $entry); | |
} | |
} | |
} | |
closedir($handle); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment