-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcron.php
More file actions
29 lines (26 loc) · 986 Bytes
/
cron.php
File metadata and controls
29 lines (26 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
/*
* Run this script reguraly (currently on DreamVids, this script is launched every 24h)
* to clear unused API accesses.
* All expired accesses will be deleted by this script.
*/
define('WORKING_DIR', 'C:/wamp/www/Storage');
define ('DIR', WORKING_DIR.'/incomings/'); // Define the accesses directory
$MyDirectory = opendir(DIR); // Open it
$i = 0; $j = 0; // Init counters
// For each file in thr directory DIR
while($Entry = @readdir($MyDirectory) ) {
// If the current file is a API access file
if (preg_match("#[a-zA-Z0-9]+_[a-zA-Z0-9]+_[0-9]+\.up#", $Entry) ) {
$path = DIR.$Entry; // Set file path
$time = file_get_contents($path); // Open'n'Read the file to get its expiration date (timestamp actually)
// If the expiration date is reached
if (time() >= $time) {
unlink($path); // File deleted
$i++; // Increase "deleted files" counter
}
$j++; // Increase "total files" counter
}
}
// Worst UX in the whole world:
echo $i.' of '.$j.' deleted.';