PHP - Dynamically Remove Folder
Submitted by razormist on Friday, October 18, 2019 - 18:18.
In this tutorial we will create a Dynamically Remove Folder using PHP. This code will dynamically remove a folder when user click the button in the table row. This code use a simple href or hypertext reference to call a script within the server that send the folder name which remove the file using removeDir() and by adding the folder path as a parameter.This is a user-friendly kind of program feel free to modify it.
We will be using PHP as a scripting language that manage a database server to handle a bulk of data per transaction. It describe as an advance technology that manage both server and control-block of your machine.
There you have it we successfully created Dynamically Remove Folder using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Getting Started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html. And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.Creating The Interface
This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
- </div>
- </nav>
- <div class="col-md-3"></div>
- <div class="col-md-6 well">
- <h3 class="text-primary">PHP - Dynamically Remove Folder</h3>
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="col-md-6">
- <table class="table table-bordered">
- <thead class="alert-info">
- <tr>
- <th>Folder Name</th>
- <th>Action</th>
- </tr>
- </thead>
- <tbody style="background-color:#fff;">
- <?php
- foreach ($files as $file){
- if($file != '.' && $file !='..'){
- ?>
- <tr>
- <td><?php echo $file?></td>
- <td><a class="btn btn-danger" href="remove.php?folder=<?php echo $file?>"><span class="glyphicon glyphicon-trash"></span> Remove</a></td>
- </tr>
- <?php
- }
- }
- ?>
- </tbody>
- </table>
- </div>
- </div>
- </body>
- </html>
Creating the Main Function
This code contains the main function of the application. This code will remove a file when the button is clicked. To do that just copy and write this block of codes inside the text editor, then save it as remove.php.- <?php
- function removeDir($dir) {
- foreach ($items as $item) {
- if ($item === '.' || $item === '..') {
- continue;
- }
- $path = $dir.'/'.$item;
- xrmdir($path);
- } else {
- }
- }
- }
- $folder = $_REQUEST['folder'];
- removeDir("files/".$folder);
- }
- }
- ?>
Add new comment
- 101 views