From 477bfff0303c8d9e4cf6435356e574dfbb9fefd7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 29 Mar 2016 15:02:00 +0200 Subject: [PATCH] Some improvements: - the old way only allowed files being placed in the same path where the script is located and not in any sub paths. This is now fixed. - Removal of old files can now be turned off --- index.php | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/index.php b/index.php index edbeaff..7ecb927 100644 --- a/index.php +++ b/index.php @@ -68,6 +68,9 @@ // Language direction 'lang_dir' => 'ltr', + + // Remove old files? + 'remove_old_files' => true, ); // =============={ Configuration End }============== @@ -237,22 +240,35 @@ function listFiles ($dir, $exclude) { $file_array = array(); $dh = opendir($dir); - while (false !== ($filename = readdir($dh))) - if (is_file($filename) && !in_array($filename, $exclude)) - $file_array[filemtime($filename)] = $filename; + while (false !== ($filename = readdir($dh))) { + $fqfn = $dir . DIRECTORY_SEPARATOR . $filename; + if (is_file($fqfn) && !in_array($filename, $exclude)) + $file_array[filemtime($fqfn)] = $filename; + } + ksort($file_array); $file_array = array_reverse($file_array, true); return $file_array; } - $file_array = listFiles($settings['uploaddir'], $data['ignores']); + // Removes old files + function removeOldFiles ($dir) { + global $file_array, $settings; + foreach ($file_array as $file) { + $fqfn = $dir . DIRECTORY_SEPARATOR . $file; + if ($settings['time_limit'] < time() - filemtime($fqfn)) + unlink($fqfn); + } + } + + $file_array = listFiles($data['uploaddir'], $data['ignores']); // Removing old files - foreach ($file_array as $file) - if ($settings['time_limit'] < time() - filemtime($file)) - unlink($file); + if ($settings['remove_old_files']) + removeOldFiles($data['uploaddir']); - $file_array = listFiles($settings['uploaddir'], $data['ignores']); + $file_array = listFiles($data['uploaddir'], $data['ignores']); + //die(print_r($file_array, TRUE)); ?> @@ -377,12 +393,13 @@