]> git.mxchange.org Git - simple-upload.git/commitdiff
Ability to mark files private
authors-ko <aleks@s-ko.net>
Wed, 15 Oct 2014 21:56:17 +0000 (22:56 +0100)
committers-ko <aleks@s-ko.net>
Wed, 15 Oct 2014 21:56:17 +0000 (22:56 +0100)
index.php

index dd3d9dcf4debd3a9647a39ebd5c18a58e3c92783..0b6cc1377fcc897b895c39da46a3e80469ab1e62 100644 (file)
--- a/index.php
+++ b/index.php
@@ -27,6 +27,9 @@
                // Allow users to delete files that they have uploaded (will enable sessions)
                allow_deletion => true,
 
+               // Allow users to mark files as hidden
+               allow_private => true,
+
                // Display file sizes
                listfiles_size => true,
 
@@ -66,7 +69,7 @@
        // Maximum upload size, set by system
        $data['max_upload_size'] = ini_get('upload_max_filesize');
 
-       if ($settings['allow_deletion']) {
+       if ($settings['allow_deletion'] || $settings['allow_private']) {
                session_start();
 
                if (!isset($_SESSION['upload_user_id']))
                }
 
                if (move_uploaded_file($data['tmp_name'], $data['upload_target_file'])) {
-                       if ($settings['allow_deletion'])
+                       if ($settings['allow_deletion'] || $settings['allow_private'])
                                $_SESSION['upload_user_files'][] = $data['target_file_name'];
                        echo $settings['url'] .  $data['target_file_name'] . "\n";
                } else {
                }
        }
 
+
+
        if (isset($_FILES['file'])) {
                if ($settings['debug']) {
                        // Displaying debug information
                exit;
        }
 
-       if ($settings['allow_deletion'])
-               if (isset($_POST))
+       if (isset($_POST)) {
+               if ($settings['allow_deletion'])
                        if ($_POST['action'] === 'delete')
-                               if (in_array($_POST['target'], $_SESSION['upload_user_files']))
+                               if (in_array(substr($_POST['target'], 1), $_SESSION['upload_user_files']) || in_array($_POST['target'], $_SESSION['upload_user_files']))
                                        if (file_exists($_POST['target'])) {
                                                unlink($_POST['target']);
                                                echo 'File has been removed';
                                                exit;
                                        }
 
+               if ($settings['allow_private'])
+                       if ($_POST['action'] === 'privatetoggle')
+                               if (in_array(substr($_POST['target'], 1), $_SESSION['upload_user_files']) || in_array($_POST['target'], $_SESSION['upload_user_files']))
+                                       if (file_exists($_POST['target'])) {
+                                               if ($_POST['target'][0] === '.') {
+                                                       rename($_POST['target'], substr($_POST['target'], 1));
+                                                       echo 'File has been made visible';
+                                               } else {
+                                                       rename($_POST['target'], '.' . $_POST['target']);
+                                                       echo 'File has been hidden';
+                                               }
+                                               exit;
+                                       }
+       }
+
        function ListFiles ($dir, $exclude) {
                $file_array = array();
                $dh = opendir($dir);
                                font-family: sans-serif;
                        }
 
-                       h1 {
+                       body > h1 {
                                display: block;
                                background: rgba(255, 255, 255, 0.05);
                                padding: 8px 16px;
                                margin: 0;
                        }
 
-                       form {
+                       body > form {
                                display: block;
                                background: rgba(255, 255, 255, 0.075);
                                padding: 16px 16px;
                                margin: 0;
                        }
 
-                       p {
+                       body > p {
                                display: block;
                                background: rgba(255, 255, 255, 0.075);
                                padding: 4px 16px;
                                text-align: center;
                        }
 
-                       ul {
+                       body > ul {
                                display: block;
                                margin: 0;
                                padding: 0;
                        }
 
-                       ul > li {
+                       body > ul > li {
                                display: block;
                                margin: 0;
                                padding: 0;
                        }
 
-                       ul > li > a {
+                       body > ul > li > a {
                                display: block;
                                margin: 0 0 1px 0;
                                list-style: none;
                                opacity: 0.5;
                        }
 
-                       ul > li > a > span {
+                       body > ul > li > a:hover {
+                               opacity: 1;
+                       }
+
+                       body > ul > li > a:active {
+                               opacity: 0.5;
+                       }
+
+                       body > ul > li > a > span {
                                float: right;
                                font-size: 90%;
                        }
 
-                       ul > li > a:hover {
+                        body > ul > li > form {
+                               display: inline-block;
+                               padding: 0;
+                               margin: 0;
+                       }
+
+                       body > ul > li.owned {
+                               margin: 8px;
+                       }
+
+                       body > ul > li > form > button {
+                               opacity: 0.5;
+                               display: inline-block;
+                               padding: 4px 16px;
+                               margin: 0;
+                               border: 0;
+                               background: rgba(255, 255, 255, 0.1);
+                               color: inherit;
+                       }
+
+                       body > ul > li > form > button:hover {
                                opacity: 1;
                        }
+
+                       body > ul > li > form > button:active {
+                               opacity: 0.5;
+                       }
                </style>
        </head>
        <body>
                                        $file_array = ListFiles($settings['uploaddir'], array('.', '..', $data['scriptname']));
                                        foreach ($file_array as $mtime => $filename) {
                                                $file_info = array();
+                                               $file_owner = false;
+                                               $file_private = $filename[0] === '.';
 
                                                if ($settings['listfiles_size'])
                                                        $file_info[] = FormatSize(filesize($filename));
                                                if ($settings['listfiles_size'])
                                                        $file_info[] = date($settings['listfiles_date_format'], $mtime);
 
-                                               if ($settings['allow_deletion'])
-                                                       if (in_array($filename, $_SESSION['upload_user_files']))
-                                                               $file_info[] = '<form action="' . $data['scriptname'] . '" method="POST"><input type="hidden" name="target" value="' . $filename . '" /><input type="hidden" name="action" value="delete" /><button type="submit">delete</button></form>';
+                                               if ($settings['allow_deletion'] || $settings['allow_private'])
+                                                       if (in_array(substr($filename, 1), $_SESSION['upload_user_files']) || in_array($filename, $_SESSION['upload_user_files']))
+                                                               $file_owner = true;
 
                                                $file_info = implode(', ', $file_info);
 
                                                if (strlen($file_info) > 0)
                                                        $file_info = ' (' . $file_info . ')';
 
-                                               echo "<li><a href=\"$filename\" target=\"_blank\">$filename<span>$file_info</span></a></li>";
+                                               $class = '';
+                                               if ($file_owner)
+                                                       $class = 'owned';
+
+                                               if (!$file_private || $file_owner) {
+                                                       echo "<li class=\"' . $class . '\">";
+
+                                                       echo "<a href=\"$filename\" target=\"_blank\">$filename<span>$file_info</span></a>";
+
+                                                       if ($file_owner) {
+                                                               if ($settings['allow_deletion'])
+                                                                       echo '<form action="' . $data['scriptname'] . '" method="POST"><input type="hidden" name="target" value="' . $filename . '" /><input type="hidden" name="action" value="delete" /><button type="submit">delete</button></form>';
+
+                                                               if ($settings['allow_private'])
+                                                                       if ($file_private)
+                                                                               echo '<form action="' . $data['scriptname'] . '" method="POST"><input type="hidden" name="target" value="' . $filename . '" /><input type="hidden" name="action" value="privatetoggle" /><button type="submit">make public</button></form>';
+                                                                       else
+                                                                               echo '<form action="' . $data['scriptname'] . '" method="POST"><input type="hidden" name="target" value="' . $filename . '" /><input type="hidden" name="action" value="privatetoggle" /><button type="submit">make private</button></form>';
+                                                       }
+
+                                                       echo "</li>";
+                                               }
                                        }
                                ?>
                        </ul>