From: s-ko Date: Sat, 27 Sep 2014 20:17:37 +0000 (+0100) Subject: Ability to remove files X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=71b3084918eb66ff17afb0121ad8e4960684b980;p=simple-upload.git Ability to remove files --- diff --git a/index.php b/index.php index 87c5a8c..778fd56 100644 --- a/index.php +++ b/index.php @@ -24,6 +24,9 @@ // Display list uploaded files listfiles => true, + // Allow users to delete files that they have uploaded (will enable sessions) + allow_deletion => true, + // Display file sizes listfiles_size => true, @@ -63,6 +66,16 @@ // Maximum upload size, set by system $data['max_upload_size'] = ini_get('upload_max_filesize'); + if ($settings['allow_deletion']) { + session_start(); + + if (!isset($_SESSION['upload_user_id'])) + $_SESSION['upload_user_id'] = rand(1000, 9999); + + if (!isset($_SESSION['upload_user_files'])) + $_SESSION['upload_user_files'] = array(); + } + if ($settings['debug']) { // Enabling error reporting error_reporting(E_ALL); @@ -79,6 +92,13 @@ echo '
';
 		print_r($data);
 		echo '
'; + echo ''; + + // Displaying debug information + echo '

Debugging information: _SESSION

'; + echo '
';
+		print_r($_SESSION);
+		echo '
'; } function FormatSize ($bytes) { @@ -93,7 +113,6 @@ return ceil($bytes) . ' ' . $units[$pow]; } - if (isset($_FILES['file']) && strlen($_FILES['file']['name']) > 1) { $data['uploaded_file_name'] = basename($_FILES['file']['name']); $data['target_file_name'] = $data['uploaded_file_name']; @@ -104,7 +123,7 @@ $data['target_file_name'] .= $settings['random_name_alphabet'][rand(0, strlen($settings['random_name_alphabet']) - 1)]; if ($settings['random_name_keep_type']) $data['target_file_name'] .= '.' . pathinfo($data['uploaded_file_name'], PATHINFO_EXTENSION); - } while (file_exists($data['target_file_name'])) + } while (file_exists($data['target_file_name'])); } $data['upload_target_file'] = $data['uploaddir'] . DIRECTORY_SEPARATOR . $data['target_file_name']; $data['tmp_name'] = $_FILES['file']['tmp_name']; @@ -118,6 +137,8 @@ } if (move_uploaded_file($data['tmp_name'], $data['upload_target_file'])) { + if ($settings['allow_deletion']) + $_SESSION['upload_user_files'][] = $data['target_file_name']; echo $data['pageurl'] . $data['upload_target_file']; exit; // echo 'File: ' . $data['uploaded_file_name'] . ' successfully uploaded:
'; @@ -128,9 +149,20 @@ exit; } } + + if ($settings['allow_deletion']) + if (isset($_POST)) + if ($_POST['action'] === 'delete') + if (in_array($_POST['target'], $_SESSION['upload_user_files'])) + if (file_exists($_POST['target'])) { + unlink($_POST['target']); + echo 'File has been removed'; + exit; + } ?> - + + Upload files