From: muchweb Date: Wed, 14 Jan 2015 22:03:25 +0000 (+0000) Subject: Verious improvements X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2c9e2591cfe5608ecae5e0df8ede49829d7c8eca;p=simple-upload.git Verious improvements --- diff --git a/index.php b/index.php index 6d65ba6..461ee3a 100644 --- a/index.php +++ b/index.php @@ -17,6 +17,9 @@ // =============={ Configuration Begin }============== $settings = array( + // Website title + title => 'strace.club', + // Directory to store uploaded files uploaddir => '.', @@ -56,61 +59,67 @@ // Amount of seconds that each file should be stored for (0 for no limit) time_limit => 0, + // Files that will be ignored + ignores = array('.', '..', 'LICENSE', 'README.md'), ); // =============={ Configuration End }============== - - - - $data = array(); // Name of this file $data['scriptname'] = pathinfo(__FILE__, PATHINFO_BASENAME); + // Adding current script name to ignore list + $data['ignores'][] = $data['scriptname']; + // Use canonized path $data['uploaddir'] = realpath($settings['uploaddir']); // Maximum upload size, set by system $data['max_upload_size'] = ini_get('upload_max_filesize'); + // If file deletion or private files are allowed, starting a session. + // This is required for user authentification if ($settings['allow_deletion'] || $settings['allow_private']) { session_start(); + // 'User ID' if (!isset($_SESSION['upload_user_id'])) - $_SESSION['upload_user_id'] = rand(1000, 9999); + $_SESSION['upload_user_id'] = rand(100000, 999999); + // List of filenames that were uploaded by this user if (!isset($_SESSION['upload_user_files'])) $_SESSION['upload_user_files'] = array(); } + // If debug is enabled, logging all variables if ($settings['debug']) { - // Enabling error reporting error_reporting(E_ALL); error_reporting(1); // Displaying debug information - echo '

Debugging information: settings

'; + echo '

Settings:

'; echo '
';
 		print_r($settings);
 		echo '
'; // Displaying debug information - echo '

Debugging information: data

'; + echo '

Data:

'; echo '
';
 		print_r($data);
 		echo '
'; echo ''; // Displaying debug information - echo '

Debugging information: _SESSION

'; + echo '

SESSION:

'; echo '
';
 		print_r($_SESSION);
 		echo '
'; } + // Format file size function FormatSize ($bytes) { $units = array('B', 'KB', 'MB', 'GB', 'TB'); @@ -123,14 +132,16 @@ return ceil($bytes) . ' ' . $units[$pow]; } + // Rotating a two-dimensional array function DiverseArray ($vector) { $result = array(); - foreach($vector as $key1 => $value1) - foreach($value1 as $key2 => $value2) + foreach ($vector as $key1 => $value1) + foreach ($value1 as $key2 => $value2) $result[$key2][$key1] = $value2; return $result; } + // Handling file upload function UploadFile ($file_data) { global $settings; global $data; @@ -151,7 +162,7 @@ } $data['upload_target_file'] = $data['uploaddir'] . DIRECTORY_SEPARATOR . $data['target_file_name']; - // Do now allow to rewrite files + // Do now allow to overwriting files if (file_exists($data['upload_target_file'])) { echo 'File name already exists' . "\n"; return; @@ -168,21 +179,8 @@ } - + // Files are being POSEed. Uploading them one by one. if (isset($_FILES['file'])) { - if ($settings['debug']) { - // Displaying debug information - echo '

Debugging information: data

'; - echo '
';
-			print_r($data);
-			echo '
'; - // Displaying debug information - echo '

Debugging information: file

'; - echo '
';
-			print_r($_FILES);
-			echo '
'; - } - header('Content-type: text/plain'); if (is_array($_FILES['file'])) { $file_array = DiverseArray($_FILES['file']); @@ -193,6 +191,7 @@ exit; } + // Other file functions (delete, private). if (isset($_POST)) { if ($settings['allow_deletion']) if ($_POST['action'] === 'delete') @@ -218,6 +217,7 @@ } } + // List files in a given directory, excluding certain files function ListFiles ($dir, $exclude) { $file_array = array(); $dh = opendir($dir); @@ -233,7 +233,7 @@ - strace.club + <?=$settings['title']?> -

strace.club

+

Maximum upload size:
@@ -346,7 +346,7 @@