summaryrefslogtreecommitdiffstats
path: root/backend/php-file/index.php
blob: 054ce475181440c542beb2327614c664695e685b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
	$a = (isset($_GET["action"]) ? $_GET["action"] : false);
	switch ($a) {
		case "list":
			$files = glob("data/*");
			foreach ($files as $file) {
				$name = basename($file);
				echo $name."\n";
			}
		break;
		case "save":
			$keyword = (isset($_GET["keyword"]) ? $_GET["keyword"] : "");
			$keyword = "data/".basename($keyword);
			$f = fopen($keyword, "w");
			$data = file_get_contents("php://input");
			if (get_magic_quotes_gpc() || get_magic_quotes_runtime()) {
			   $data = stripslashes($data);
			}
			fwrite($f, $data);
			fclose($f);
			header("HTTP/1.0 201 Created");			
		break;
		case "load":
			$keyword = (isset($_GET["keyword"]) ? $_GET["keyword"] : "");
			$keyword = "data/".basename($keyword);
			if (!file_exists($keyword)) {
				header("HTTP/1.0 404 Not Found");
			} else {
				header("Content-type: text/xml");
				echo file_get_contents($keyword);
			}
		break;
		default: header("HTTP/1.0 501 Not Implemented");
	}
?>