]> git.mxchange.org Git - simple-upload.git/commitdiff
Changed settings variables
authors-ko <aleks@s-ko.net>
Thu, 25 Sep 2014 21:36:32 +0000 (22:36 +0100)
committers-ko <aleks@s-ko.net>
Thu, 25 Sep 2014 21:36:32 +0000 (22:36 +0100)
index.php

index ab6600a4b29711f41f7c8ad958d1741e5879ba46..9f1ce32f594dfbc4b17d6a5d5ec85d94fc5cbb79 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,7 +1,4 @@
 <?php
 <?php
-    error_reporting(E_ALL);
-    error_reporting(1);
-
        /*
                This program is free software: you can redistribute it and/or modify
                it under the terms of the GNU General Public License as published by
        /*
                This program is free software: you can redistribute it and/or modify
                it under the terms of the GNU General Public License as published by
                listfiles => true,
 
 
                listfiles => true,
 
 
+               // Randomize file names
+               random_name_len => false,
+
+
+               // Random file name letters
+               random_name_alphabet => 'qwertyuiodfgjkcvbnm',
+
+
                // Display debugging information
                // Display debugging information
-               debug => false
+               debug => true
 
        );
 
        // ============== Configuration end  ==============
 
 
        );
 
        // ============== 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
 
        // 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']) {
        if ($settings['debug']) {
-               echo '<h1>Debugging information</h1>';
+        // Enabling error reporting
+        error_reporting(E_ALL);
+        error_reporting(1);
+
+        // Displaying debug information
+               echo '<h1>Debugging information: settings</h1>';
                echo '<pre>';
                print_r($settings);
                echo '</pre>';
                echo '<pre>';
                print_r($settings);
                echo '</pre>';
+
+        // Displaying debug information
+               echo '<h1>Debugging information: data</h1>';
+               echo '<pre>';
+               print_r($data);
+               echo '</pre>';
        }
 
        if (isset($_FILES['file']) && strlen($_FILES['file']['name']) > 1) {
        }
 
        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 '<h1>Debugging information: data</h1>';
+               echo '<pre>';
+               print_r($data);
+               echo '</pre>';
+       }
 
 
-               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;
                        exit;
-                       // echo 'File: <b>' . $upload_file_name . '</b> successfully uploaded:<br />';
+                       // echo 'File: <b>' . $data['uploaded_file_name'] . '</b> successfully uploaded:<br />';
                        // echo 'Size: <b>'. number_format($_FILES['file']['size'] / 1024, 3, '.', '') .'KB</b><br />';
                        // echo 'Size: <b>'. number_format($_FILES['file']['size'] / 1024, 3, '.', '') .'KB</b><br />';
-                       // echo 'File /URL: <b><a href="http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath.'">http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath.'</a></b>';
+                       // echo 'File /URL: <b><a href="http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$data['upload_target_file'].'">http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$data['upload_target_file'].'</a></b>';
                } else {
                        echo 'Error: unable to upload the file.';
                        exit;
                } else {
                        echo 'Error: unable to upload the file.';
                        exit;
                </style>
        </head>
        <body>
                </style>
        </head>
        <body>
-               <form action="<?= $settings['scriptpath'] ?>" method="POST" enctype="multipart/form-data" class="dropzone" id="my-awesome-dropzone">
+               <form action="<?= $data['scriptname'] ?>" method="POST" enctype="multipart/form-data" class="dropzone" id="my-awesome-dropzone">
                        <div class="fallback">
                                Choose File: <input type="file" name="file" /><br />
                                <input type="submit" value="Upload" />
                        <div class="fallback">
                                Choose File: <input type="file" name="file" /><br />
                                <input type="submit" value="Upload" />
                                <?php
                                        $dh = opendir($settings['uploaddir']);
                                        while (false !== ($filename = readdir($dh)))
                                <?php
                                        $dh = opendir($settings['uploaddir']);
                                        while (false !== ($filename = readdir($dh)))
-                                               if (!in_array($filename, array('.', '..', $settings['scriptname'])))
+                                               if (!in_array($filename, array('.', '..', $data['scriptname'])))
                                                        echo "<li><a href=\"$filename\">$filename</a></li>";
                                ?>
                        </ul>
                                                        echo "<li><a href=\"$filename\">$filename</a></li>";
                                ?>
                        </ul>