X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=index.php;h=0b6cc1377fcc897b895c39da46a3e80469ab1e62;hb=9e386b2622091e46b475f5e17108aa847a6be4cb;hp=513d7d14fc567a6b6f83c1c20db660d8d46a2be3;hpb=909ad54f74dbe53dbae1f2655f6210dfc5cebf79;p=simple-upload.git diff --git a/index.php b/index.php index 513d7d1..0b6cc13 100644 --- a/index.php +++ b/index.php @@ -18,70 +18,92 @@ $settings = array( - // Directory to store uploaded files uploaddir => '.', - // Display list uploaded files listfiles => true, + // 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, - // Display file dates listfiles_date => true, - // Display file dates format listfiles_date_format => 'F d Y H:i:s', - // Randomize file names (number of 'false') - random_name_len => 10, - + random_name_len => 8, // Keep filetype information (if random name is activated) random_name_keep_type => true, - // Random file name letters - random_name_alphabet => 'qwertyuiodfgjkcvbnm', - + random_name_alphabet => 'qazwsxedcrfvtgbyhnujmikolp1234567890', // Display debugging information - debug => false + debug => false, + + // Complete URL to your directory (including tracing slash) + url => 'http://strace.club/', ); // ============== Configuration end ============== - $data = array(); + $data = array(); // Name of this file $data['scriptname'] = pathinfo(__FILE__, PATHINFO_BASENAME); - // URL to upload page - $data['pageurl'] = "http" . (($_SERVER['SERVER_PORT']==443) ? "s://" : "://") . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']) . '/'; + // Use canonized path + $data['uploaddir'] = realpath($settings['uploaddir']); + + // Maximum upload size, set by system + $data['max_upload_size'] = ini_get('upload_max_filesize'); + + if ($settings['allow_deletion'] || $settings['allow_private']) { + 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); - error_reporting(1); - // Displaying debug information - echo '

Debugging information: settings

'; + + // Enabling error reporting + error_reporting(E_ALL); + error_reporting(1); + + // Displaying debug information + echo '

Debugging information: settings

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

Debugging information: data

'; + // Displaying debug information + echo '

Debugging information: data

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

Debugging information: _SESSION

'; + echo '
';
+		print_r($_SESSION);
+		echo '
'; } function FormatSize ($bytes) { @@ -96,245 +118,271 @@ return ceil($bytes) . ' ' . $units[$pow]; } + function DiverseArray ($vector) { + $result = array(); + foreach($vector as $key1 => $value1) + foreach($value1 as $key2 => $value2) + $result[$key2][$key1] = $value2; + return $result; + } + + function UploadFile ($file_data) { + global $settings; + global $data; + global $_SESSION; + + $data['uploaded_file_name'] = basename($file_data['name']); + $data['target_file_name'] = $file_data['uploaded_file_name']; + if ($settings['random_name_len'] !== false) { + do { + $data['target_file_name'] = ''; + while (strlen($data['target_file_name']) < $settings['random_name_len']) + $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'])); + } + $data['upload_target_file'] = $data['uploaddir'] . DIRECTORY_SEPARATOR . $data['target_file_name']; + $data['tmp_name'] = $file_data['tmp_name']; - 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']; - if ($settings['random_name_len'] !== false) { - $data['target_file_name'] = ''; - while (strlen($data['target_file_name']) < $settings['random_name_len']) - $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); - } - $data['upload_target_file'] = $settings['uploaddir'] . DIRECTORY_SEPARATOR . $data['target_file_name']; - $data['tmp_name'] = $_FILES['file']['tmp_name']; - - if ($settings['debug']) { - // Displaying debug information - echo '

Debugging information: data

'; - echo '
';
-    		print_r($data);
-    		echo '
'; - } + if (file_exists($data['upload_target_file'])) { + echo 'File name already exists' . "\n"; + return; + } if (move_uploaded_file($data['tmp_name'], $data['upload_target_file'])) { - echo $data['pageurl'] . $data['upload_target_file']; - exit; - // echo 'File: ' . $data['uploaded_file_name'] . ' successfully uploaded:
'; - // echo 'Size: '. number_format($_FILES['file']['size'] / 1024, 3, '.', '') .'KB
'; - // echo 'File /URL: http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$data['upload_target_file'].''; + if ($settings['allow_deletion'] || $settings['allow_private']) + $_SESSION['upload_user_files'][] = $data['target_file_name']; + echo $settings['url'] . $data['target_file_name'] . "\n"; } else { echo 'Error: unable to upload the file.'; - exit; } } + + + + 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 '
'; + } + + if (is_array($_FILES['file'])) { + $file_array = DiverseArray($_FILES['file']); + foreach ($file_array as $file_data) + UploadFile($file_data); + } else + UploadFile($_FILES['file']); + exit; + } + + if (isset($_POST)) { + if ($settings['allow_deletion']) + if ($_POST['action'] === 'delete') + 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); + while (false !== ($filename = readdir($dh))) + if (is_file($filename) && !in_array($filename, $exclude)) + $file_array[filemtime($filename)] = $filename; + ksort($file_array); + $file_array = array_reverse($file_array, true); + return $file_array; + } + ?> - + - Upload files - - + + strace.club -
-
- Choose File:
- -
+

strace.club

+ + Maximum upload size:
+
- Uploaded files:
+

Uploaded files:

+ Fork me on GitHub +