]> git.mxchange.org Git - simple-upload.git/blobdiff - index.php
Description for uploader website
[simple-upload.git] / index.php
index e32486df394cb1f9427da0cc6021cc92e9fa6196..9d8a4e867be41a75c70eb8a12dc63a3cc9fd847c 100644 (file)
--- a/index.php
+++ b/index.php
                // Website title
                'title' => 'strace.club',
 
-               // Directory to store uploaded files
+               // Description for this website
+               'description' => '',
+
+               // Base path (auto-detection)
+               'base_path' => dirname(__FILE__) . DIRECTORY_SEPARATOR,
+
+               // Directory to store uploaded files (relative to base_path)
                'uploaddir' => '.',
 
                // Display list uploaded files
        $data['ignores'][] = basename($data['scriptname']);
 
        // Use canonized path
-       $data['uploaddir'] = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . $settings['uploaddir']);
+       $data['uploaddir'] = realpath($settings['base_path'] . $settings['uploaddir']);
 
        // Maximum upload size, set by system
        $data['max_upload_size'] = ini_get('upload_max_filesize');
                // Do now allow to overwriting files
                if (isReadableFile($file_data['upload_target_file'])) {
                        echo 'File name already exists' . "\n";
-                       return;
+                       return false;
                }
 
                // Moving uploaded file OK
                if (move_uploaded_file($file_data['tmp_name'], $file_data['upload_target_file'])) {
-                       if ($settings['allow_deletion'] || $settings['allow_private'])
+                       if ($settings['listfiles'] && ($settings['allow_deletion'] || $settings['allow_private']))
                                $_SESSION['upload_user_files'][] = $file_data['target_file_name'];
                        echo $settings['url'] .  $file_data['target_file_name'] . "\n";
+
+                       // Return target file name for later handling
+                       return $file_data['upload_target_file'];
                } else {
                        echo 'Error: unable to upload the file.';
+                       return false;
                }
        }
 
                header('Content-type: text/plain');
                if (is_array($_FILES['file'])) {
                        $file_array = diverseArray($_FILES['file']);
-                       foreach ($file_array as $file_data)
-                               uploadFile($file_data);
-               } else
-                       uploadFile($_FILES['file']);
+                       foreach ($file_array as $file_data) {
+                               $targetFile = uploadFile($file_data);
+                       }
+               } else {
+                       $targetFile = uploadFile($_FILES['file']);
+               }
                exit;
        }
 
                global $data;
 
                $file_array = array();
+
                $dh = opendir($dir);
-                       while ($filename = readdir($dh)) {
-                               $fqfn = $dir . DIRECTORY_SEPARATOR . $filename;
-                               if (isReadableFile($fqfn) && !in_array($filename, $data['ignores']))
-                                       $file_array[filemtime($fqfn)] = $filename;
-                       }
+
+               while ($filename = readdir($dh)) {
+                       $fqfn = $dir . DIRECTORY_SEPARATOR . $filename;
+                       if (isReadableFile($fqfn) && !in_array($filename, $data['ignores']))
+                               $file_array[filemtime($fqfn)] = $filename;
+               }
 
                ksort($file_array);
+
                $file_array = array_reverse($file_array, true);
+
                return $file_array;
        }
 
        </head>
        <body>
                <h1><?=$settings['title']?></h1>
+               <p><?=$settings['description']?></p>
                <form action="<?= $data['scriptname'] ?>" method="post" enctype="multipart/form-data" class="dropzone" id="simpleupload-form">
                        Maximum upload size: <?php echo $data['max_upload_size']; ?><br />
                        <input type="file" name="file[]" id="simpleupload-input" />