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

  • SEARCH
  • Home
  • 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 8646253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:45:35+00:00 2026-06-12T12:45:35+00:00

Slightly different task this time round, I wish to delete files inside a specific

  • 0

Slightly different task this time round, I wish to delete files inside a specific directory with the click of a drop down option (Which calls the file name) and then followed this by a submit button click.

<?php
$myFile = "testFile.txt";
unlink($myFile);
?>

I am under the idea that the above code is what I need. However I make the “testFile.txt” is replaced with something along the lines of:

<?php $myFile = ?><html>Dropdown code here to list all files in directory</html><?php ;    unlink($myFile);
    ?>

I’m still editing and chopping the snippet so sorry if the response takes a while.

Edit: I was wondering if you could help me with creating it so that it is a drop down box of all the files uploaded into the directory /uploads/ so I can delete them without searching.

Thanks in advance everybody.

edit:

Ok, So after some help I have achieved this so far:

<?php
$path = "uploads/";
$handle = opendir($path);   

while ($file = readdir($handle)) {
    if (substr($file,0,1) != ".") {
    echo "<option value ='$file'></option>";
    }   
}
closedir($handle);  
?>

However this won’t display the files in the options, I know im missing something here. I used your guys resources and:

http://php.net/manual/en/function.readdir.php

  • 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-12T12:45:36+00:00Added an answer on June 12, 2026 at 12:45 pm

    Here’s one way – it may not be perfect, I haven’t tested it

    dir will get you a listing of files in a directory, you can use that to populate an options list in PHP, and echo it out to your HTML page.

    PHP:

    $d = dir("myDirectory");
    
    $files = array();
    while (false !== ($entry = $d->read())) {
        if($entry == '.' || $entry == '..') continue;
        $files[] = '<option value="'.$entry.'">'.$entry.'</option>';
    }
    
    $options = implode('',$files);
    

    HTML:

    <form...>
        <select name="file_delete"><?= $options;?></select>
        <input type="submit"... />
    </form>
    

    Then you can get the file from the $_POST or $_GET array after the user submits the form.

    Hope this helps.

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

Sidebar

Related Questions

slightly different question about variance this time. I take it from experimentation that C#
I know this question has been done but I have a slightly different twist
I read all the similar questions but mine is slightly different. The first time
I'm using a rake task to move data between databases with slightly different schemas.
I saw this post but mine is slightly different: Rails ActionMailer with multiple SMTP
If you use this code in Silverlight and WPF you get slightly different results?
I believe this question is slightly different than similar ones asked on here before
I'm going to re-ask this question in a slightly different way. Say I have
This is a slightly different question to this one ([ Accessing a method from
This is NOT duplicate of my earlier post (its is slightly different) But this

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.