From: s-ko Date: Sat, 27 Sep 2014 20:45:46 +0000 (+0100) Subject: Added multiple upload and removed drag&drop temporarely X-Git-Url: https://git.mxchange.org/?p=simple-upload.git;a=commitdiff_plain;h=220719553fb1c5b75f365a7cd80d12a04d832830 Added multiple upload and removed drag&drop temporarely --- diff --git a/index.php b/index.php index 778fd56..ddeea7f 100644 --- a/index.php +++ b/index.php @@ -113,9 +113,21 @@ 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']; + function diverse_array ($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'] = ''; @@ -126,30 +138,49 @@ } 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']; + $data['tmp_name'] = $file_data['tmp_name']; + - if ($settings['debug']) { - // Displaying debug information - echo '

Debugging information: data

'; echo '
';
     		print_r($data);
     		echo '
'; - } + 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 $data['pageurl'] . $data['upload_target_file'] . "\n"; // 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'].''; } 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 = diverse_array($_FILES['file']); + foreach ($file_array as $file_data) + UploadFile($file_data); + } else + UploadFile($_FILES['file']); + exit; + } + if ($settings['allow_deletion']) if (isset($_POST)) if ($_POST['action'] === 'delete') @@ -163,177 +194,7 @@ - Upload files - - - + Simple PHP Upload

Simple PHP Upload

@@ -342,7 +203,7 @@

- Choose File:
+ Choose File: