From: s-ko Date: Sat, 27 Sep 2014 19:56:26 +0000 (+0100) Subject: Added check if file exists X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=956d8bb8b82e960fc5f27fa61a5c82e5708f52d9;p=simple-upload.git Added check if file exists --- diff --git a/index.php b/index.php index 715b4ff..87c5a8c 100644 --- a/index.php +++ b/index.php @@ -18,41 +18,32 @@ $settings = array( - // Directory to store uploaded files uploaddir => '.', - // Display list uploaded files listfiles => 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 => 4, // Keep filetype information (if random name is activated) random_name_keep_type => true, - // Random file name letters - random_name_alphabet => 'qwertyuiodfgjkcvbnm', - + random_name_alphabet => 'qwertyuiopasdfghjklzxcvbnm', // Display debugging information - debug => $_SERVER['SERVER_NAME'] === 'localhost' + debug => ($_SERVER['SERVER_NAME'] === 'localhost') ); @@ -78,13 +69,13 @@ error_reporting(1); // Displaying debug information - echo '

Debugging information: settings

'; + echo '

Debugging information: settings

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

Debugging information: data

'; + echo '

Debugging information: data

'; echo '
';
 		print_r($data);
 		echo '
'; @@ -107,18 +98,20 @@ $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); + 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'] = $_FILES['file']['tmp_name']; if ($settings['debug']) { // Displaying debug information - echo '

Debugging information: data

'; + echo '

Debugging information: data

'; echo '
';
     		print_r($data);
     		echo '
';