Hey I need a PHP script or function that can display all changes made to any files within the directory. For example if I edit index.php, this function will show me "$variable edited" when called up. Any good ideas on this? Thanks
To achieve this, you would either have to edit the files via a script that logs every change made, or you need a database with all file information and a script that goes through the database each time it's called and compares the file values with the values in the table. Unless you have a good reason to do this, I think it's a silly thing. Do you have several people working on your files and you want to know if something has been edited? Maybe something like this is enough, which would show all files in a directory that have been edited within the past X days. <?php $path = '.'; $days = 3; $now = time(); foreach (glob("{$path}/*.*") AS $file) { if (filemtime($file) > ($now - 3600 * 24 * $days)) { echo "{$file} has been edited within the last {$days} days.<br />\n"; } } ?> PHP:
Thanks, tried that but it tells me glob() is undefined... Yes I have many people working on this website, which is why I just need to show what has been edited in the past.. I'm not too experienced with the glob() function; how can I fix that? Thanks!
You must be using an old version of PHP (tell your host to upgrade) Alternatively you can use the good old opendir() version though: <?php $path = './path/to/files/'; $days = 3; // Don't edit below $dir = @opendir($path) OR die("Cannot open directory: {$path}"); $now = time(); while (($file = readdir($dir)) !== false) { $file = "{$path}{$file}"; $lastedit = filemtime($file); if (is_file($file) AND $lastedit > ($now - 3600 * 24 * $days)) { printf("<a href=\"%s\">%s</a> has been edited within the last %d days (%s)<br />\n", $file, $file, $days, date('dS M @ H:i:s', $lastedit)); } } closedir($dir); ?> PHP: