From: s-ko Date: Wed, 15 Oct 2014 21:56:17 +0000 (+0100) Subject: Ability to mark files private X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d03faa036066bc5f9af5176698beae3993d1777f;p=simple-upload.git Ability to mark files private --- diff --git a/index.php b/index.php index dd3d9dc..0b6cc13 100644 --- 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'])) @@ -148,7 +151,7 @@ } 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 { @@ -156,6 +159,8 @@ } } + + if (isset($_FILES['file'])) { if ($settings['debug']) { // Displaying debug information @@ -179,16 +184,31 @@ 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); @@ -213,7 +233,7 @@ font-family: sans-serif; } - h1 { + body > h1 { display: block; background: rgba(255, 255, 255, 0.05); padding: 8px 16px; @@ -221,14 +241,14 @@ 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; @@ -236,19 +256,19 @@ 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; @@ -259,14 +279,46 @@ 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; + } @@ -282,6 +334,8 @@ $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)); @@ -289,16 +343,37 @@ 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[] = '
'; + 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 "
  • $filename$file_info
  • "; + $class = ''; + if ($file_owner) + $class = 'owned'; + + if (!$file_private || $file_owner) { + echo "
  • "; + + echo "$filename$file_info"; + + if ($file_owner) { + if ($settings['allow_deletion']) + echo '
    '; + + if ($settings['allow_private']) + if ($file_private) + echo '
    '; + else + echo '
    '; + } + + echo "
  • "; + } } ?>