1

This is a simple directory listing, which allows you to navigate and go back. Everything works until I click the "Delete" button. The form is sent, but no values appear in the URL and therefore the $_GET is empty.

This is the code that attempts to send a test value when clicking "Delete".

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Directory listing</title>
    </head>
    <body>
        <?php
        $path = empty($_GET["path"]) ? "D:/" : $_GET["path"];
        ?>
        <a href="index.php?path=<?= substr($path, 0, strrpos($path, "/", -2)) . "/" ?>"><=</a>
        <?php
        $dir = opendir($path);

        while ($fileName = readdir($dir)) :
            if ($fileName != "." && $fileName != "..") :
                ?>
                <div>
                    <?php
                    if (is_dir($path . $fileName)) :
                        ?>
                        <a href="index.php?path=<?= $path . $fileName ?>/"><?= $fileName ?></a>
                        <form style="display:inline" action="index.php?path=test" method="GET">
                            <input type="submit" value="Delete" />
                        </form>
                        <?php
                    endif;
                    if (is_file($path . $fileName)) {
                        echo "$fileName";
                    }
                    ?>
                </div>
                <?php
            endif;
        endwhile;
        ?>
    </body>
</html>

I'm using Xampp v3.2.2.

Morgan
  • 907
  • 1
  • 13
  • 35
  • check out this post: http://stackoverflow.com/questions/1116019/submitting-a-get-form-with-query-string-params-and-hidden-params-disappear – BizzyBob May 01 '17 at 02:30

1 Answers1

0

Have you try to add a slash in front of your action in here ?

<form style="display:inline" action="/index.php?path=test" method="GET">
    <input type="submit" value="Delete" />
</form>
Long Kim
  • 490
  • 3
  • 9