]> git.mxchange.org Git - simple-upload.git/blobdiff - index.php
:memo: Added TODO
[simple-upload.git] / index.php
index b2a8b4fe3960a62eb8772a3226f5cddabff76468..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>
                <h1>strace.club</h1>
-               <form action="<?= $data['scriptname'] ?>" method="POST" enctype="multipart/form-data" class="dropzone" id="my-awesome-dropzone">
+               <form action="<?= $data['scriptname'] ?>" method="POST" enctype="multipart/form-data" class="dropzone" id="simpleupload-form">
                        Maximum upload size: <?php echo $data['max_upload_size']; ?><br />
-                       <input type="file" name="file[]" multiple required onchange="formname.submit();" />
+                       <input type="file" name="file[]" multiple required id="simpleupload-input"/>
                </form>
                <?php if ($settings['listfiles']) { ?>
                        <p>Uploaded files:</p>
                                        $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>
                <?php } ?>
+               <a href="https://github.com/muchweb/simple-php-upload"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
+               <script charset="utf-8">
+                       document.getElementById('simpleupload-input').onchange = function() {
+                               document.getElementById('simpleupload-form').submit();
+                       };
+               </script>
        </body>
 </html>