From: Roland Häder Date: Tue, 29 Mar 2016 13:02:00 +0000 (+0200) Subject: Some improvements: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=477bfff0303c8d9e4cf6435356e574dfbb9fefd7;p=simple-upload.git 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 --- 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 @@