]> git.mxchange.org Git - simple-upload.git/commitdiff
Some improvements:
authorRoland Häder <roland@mxchange.org>
Tue, 29 Mar 2016 13:02:00 +0000 (15:02 +0200)
committerRoland Häder <roland@mxchange.org>
Tue, 29 Mar 2016 13:02:00 +0000 (15:02 +0200)
- 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

index edbeaff746352cec21a4a3da24a9cbabc5c8f043..7ecb92709b15ea00de131bdaffec0c14b818d78c 100644 (file)
--- a/index.php
+++ b/index.php
@@ -68,6 +68,9 @@
 
                // Language direction
                'lang_dir' => 'ltr',
+
+               // Remove old files?
+               'remove_old_files' => true,
        );
        // =============={ Configuration End }==============
 
        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));
 ?>
 <!DOCTYPE html>
 <html lang="<?=$settings['lang']?>" dir="<?=$settings['lang_dir']?>">
                        <ul id="simpleupload-ul">
                                <?php
                                        foreach ($file_array as $mtime => $filename) {
+                                               $fqfn = $data['uploaddir'] . DIRECTORY_SEPARATOR . $filename;
                                                $file_info = array();
                                                $file_owner = false;
                                                $file_private = $filename[0] === '.';
 
                                                if ($settings['listfiles_size'])
-                                                       $file_info[] = formatSize(filesize($filename));
+                                                       $file_info[] = formatSize(filesize($fqfn));
 
                                                if ($settings['listfiles_size'])
                                                        $file_info[] = date($settings['listfiles_date_format'], $mtime);
                                                if (!$file_private || $file_owner) {
                                                        echo "<li class=\"' . $class . '\">";
 
-                                                       echo "<a href=\"$filename\" target=\"_blank\">$filename<span>$file_info</span></a>";
+                                                       $url = str_replace('/./', '/', sprintf('%s%s/%s', $settings['url'], $settings['uploaddir'], $filename));
+
+                                                       echo "<a href=\"$url\" target=\"_blank\">$filename<span>$file_info</span></a>";
 
                                                        if ($file_owner) {
                                                                if ($settings['allow_deletion'])