Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8483613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:09:13+00:00 2026-06-10T20:09:13+00:00

Trying to make a dropdown list, displaying files from a specific folder, with a

  • 0

Trying to make a dropdown list, displaying files from a specific folder, with a Delete button to delete the file selected.

Dropdown list:

<?php
    $dirname = "files";
    $dir = opendir($dirname);
    echo '<form action="delete.php" method="get">';
    echo '<select name="file2">';
    while(false != ($file = readdir($dir)))
    {
        if(($file != ".") and ($file != ".."))
        {
            echo "<option value=".$file.">$file</option>";
        }
    }
    echo '</select>';
    echo '<input type="submit" value="Delete" class="submit" />';
    echo '</form>';
?>

the delete.php file:

<?php
    $dirpath = "files";
    $file_to_delete = $_POST['file2'];
    if ( unlink ($dirpath.'/'.$file_to_delete) ) {
        echo $file_to_delete . " deleted.";
    } else {
        echo "Error.";
    }
?>

When I then try to selected a file and press delete, I get the following error:

Warning: unlink(files/): Is a directory in
/xxx/xxx/xxx/xxx/xxx/xxx/xxx/xxx/delete.php on
line 4 Error.

xxx’ed out due to privacy 🙂 all the files trying to be deleted are chmod 777.
its a simply .txt file I’m trying to delete.

Not sure what I’m missing or what I did wrong here… :/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:09:14+00:00Added an answer on June 10, 2026 at 8:09 pm

    It’s $_GET, because your form has method="get":

    $file_to_delete = $_GET['file2'];
    

    so:

    <?php
        $dirpath = "files";
        $file_to_delete = $_GET['file2'];
        if ( unlink ($dirpath.'/'.$file_to_delete) ) {
            echo $file_to_delete . " deleted.";
        } else {
            echo "Error.";
        }
    ?>
    

    If you want post change your form to method="post".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to php and trying to make dropdown list work with wordpress
i am trying to make a colored dropdown list with colored items (please see
I'm new to jquery and i'm trying to make a dropdown menu list like
I'm trying to get the selected value from a drop down list via jQuery.
Trying to make a dropdown list, which should be submitted if any option is
Trying to dynamically change dropdown list values from mysql database. Script seems like workin
Hi I am trying to make a drop down list for a group of
I am trying to make a dropdown menu that when you click dropdown a
I am trying to make a dropdown menu with pure html and css, but
Hi guys Im trying to make a drop-down list of countries and when the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.