2 function abort($status, $body) {
3 header("HTTP/1.1 $status");
9 abort('405 post error', "niets te doen");
10 if (!isset($_SERVER['PATH_INFO']) or strlen($_SERVER['PATH_INFO']) <= 1)
11 abort('409 input error', "geen bestand aangeleverd");
13 $filename = preg_replace('/(?:\.html)?$/', '.html', ltrim($_SERVER['PATH_INFO'], '/'), 1);
14 if (file_exists($filename) and !is_writable($filename))
15 abort('403 input error', "ongeldige bestandsnaam: $filename");
17 if (!isset($_POST['body']))
18 abort('409 input error', "geen inhoud aangeleverd");
20 $upload = $_POST['body'];
22 if (!strlen($upload)) {
23 if (file_exists($filename) and !unlink($filename))
24 abort('500 delete error', "fout bij het verwijderen van $filename");
26 print "Bestand verwijderd";
30 $prepend = '<!--#include virtual="/head.inc.html" -->'."\n\n";
31 $append = "\n".'<!--#include virtual="/foot.inc.html" -->'."\n";
33 if (!file_put_contents($filename, $prepend . $upload . $append))
34 abort('500 save error', "fout bij schrijven van $filename");
36 print "Bestand opgeslagen";