diff options
| author | David T. Sadler <davidtsadler@googlemail.com> | 2021-11-09 20:47:01 +0000 |
|---|---|---|
| committer | David T. Sadler <davidtsadler@googlemail.com> | 2021-11-09 20:47:01 +0000 |
| commit | 80d9e02ea47bfb783cc2033162ae9231551e5654 (patch) | |
| tree | 46ff8224aba31db47a5c3094a0609a297cf33ec3 /public | |
| parent | b15a095c0e5f980b63c1b229b0671227bfc64316 (diff) | |
Delete files that are no longer neededrewrite
Diffstat (limited to 'public')
| -rw-r--r-- | public/read/index.php | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/public/read/index.php b/public/read/index.php deleted file mode 100644 index 74bb4ed..0000000 --- a/public/read/index.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php declare(strict_types=1); - -error_reporting(E_ALL); - -require_once(__DIR__.'/../../includes/functions.php'); - -$config = require_once(__DIR__.'/../../config.php'); - -if ('GET' !== filter_input(INPUT_SERVER, 'REQUEST_METHOD')) { - respondAndExit(405, 'Method Not Allowed'); -} - -$requestedUrl = filter_input(INPUT_GET, 'url', FILTER_VALIDATE_URL); - -if (!$requestedUrl || strlen($requestedUrl) > $config['max_url_length']) { - respondAndExit(400, 'Bad Request'); -} - -$urls = file($config['path_to_file'], FILE_IGNORE_NEW_LINES); - -// Remove requested url from list if present. -$remaingUrls = array_diff($urls, [$requestedUrl]); - -// Count will not have changed if requested url doesn't exist in the list. -if (count($remaingUrls) === count($urls)) { - respondAndExit(404, 'Not Found'); -} - -if (!file_put_contents($config['path_to_file'], implode("\n", $remaingUrls)."\n")) { - respondAndExit(500, 'Internal Server Error'); -} - -respondAndExit(308, 'Permanent Redirect', ["Location: $requestedUrl"]); |
