From: s-ko Date: Thu, 25 Sep 2014 21:36:32 +0000 (+0100) Subject: Changed settings variables X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=10ae41112ff71c17beea35cfee5e6b520587496c;p=simple-upload.git Changed settings variables --- diff --git a/index.php b/index.php index ab6600a..9f1ce32 100644 --- a/index.php +++ b/index.php @@ -1,7 +1,4 @@ true, + // Randomize file names + random_name_len => false, + + + // Random file name letters + random_name_alphabet => 'qwertyuiodfgjkcvbnm', + + // Display debugging information - debug => false + debug => true ); // ============== Configuration end ============== - // Relative path to this file (don't edit) - $settings['scriptpath'] = $_SERVER['PHP_SELF']; + $data = array(); - // Name of this file (don't edit) - $settings['scriptname'] = pathinfo(__FILE__, PATHINFO_FILENAME) . '.php'; + // Name of this file + $data['scriptname'] = pathinfo(__FILE__, PATHINFO_BASENAME); // URL to upload page - $settings['pageurl'] = $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['REQUEST_URI']), '\\/'); + $data['pageurl'] = "http" . (($_SERVER['SERVER_PORT']==443) ? "s://" : "://") . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/'; - // Displaying debug information if ($settings['debug']) { - echo '

Debugging information

'; + // 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

'; + echo '
';
+		print_r($data);
+		echo '
'; } if (isset($_FILES['file']) && strlen($_FILES['file']['name']) > 1) { - $upload_file_name = basename($_FILES['file']['name']); - $uploadpath = $settings['uploaddir'] . DIRECTORY_SEPARATOR . $upload_file_name; - $page_url = $_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/'); + $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, count($settings['random_name_alphabet']) - 1)]; + } + $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 (move_uploaded_file($_FILES['file']['tmp_name'], $uploadpath)) { - echo 'http://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['REQUEST_URI']), '\\/') . '/' . $uploadpath; + if (move_uploaded_file($data['tmp_name'], $data['upload_target_file'])) { + echo $data['pageurl'] . $data['upload_target_file']; exit; - // echo 'File: ' . $upload_file_name . ' successfully uploaded:
'; + // 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']), '\\/').'/'.$uploadpath.''; + // 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; @@ -246,7 +274,7 @@ -
+
Choose File:
@@ -258,7 +286,7 @@ $filename"; ?>