semy13011
Exfiltration Specialist
LEVEL 1
200 XP
In this tutorial we will create a Delete Directory With Files Instantly using PHP. PHP is a server-side scripting language designed primarily for web development. Using PHP, you can let your user directly interact with the script and easily to learned its syntax. It is mostly used by a newly coders for its user friendly environment. So Let's do the 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.
Lastly, 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.
Creating Main Function
This is where the main function of the application. This code will delete the directory and the file inside of it when the button is clicked. To do this just copy and write these block of codes inside the text editor, then save it as delete.php.
There you have it we successfully created Delete Directory With Files Instantly 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!
Download
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.
Lastly, 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 - Delete Directory With Files Instantly</h3>
- <hr style="border-top:1px dotted #ccc;"/>
- <table class="table table-bordered">
- <thead class="alert-info">
- <tr>
- <th>Directory Name</th>
- <th>Action</th>
- </tr>
- </thead>
- <tbody style="background-color:#fff;">
- <?php
- $files
=
scandir
(
'files/'
)
;
- foreach
(
$files
as
$file
)
{
- if
(
$file
!=
'.'
&&
$file
!=
'..'
)
{
- ?>
- <tr>
- <td><?php
echo
$file
?>
</td>
- <td><a class="text-danger" href="delete.php?directory=<?php
echo
$file
?>
">Remove</a></td>
- </tr>
- <?php
- }
- }
- ?>
- </tbody>
- </table>
- </div>
- </body>
- </html>
Creating Main Function
This is where the main function of the application. This code will delete the directory and the file inside of it when the button is clicked. To do this just copy and write these block of codes inside the text editor, then save it as delete.php.
- <?php
- if
(
ISSET
(
$_REQUEST
[
'directory'
]
)
)
{
- $directory
=
$_REQUEST
[
'directory'
]
;
- if
(
file_exists
(
"files/"
.
$directory
)
)
{
- removeDir(
"files/"
.
$directory
)
;
- header
(
"location: index.php"
)
;
- }
- }
- function
removeDir(
$dir
)
{
- $items
=
scandir
(
$dir
)
;
- foreach
(
$items
as
$item
)
{
- if
(
$item
===
'.'
||
$item
===
'..'
)
{
- continue
;
- }
- $path
=
$dir
.
'/'
.
$item
;
- if
(
is_dir
(
$path
)
)
{
- xrmdir(
$path
)
;
- }
else
{
- unlink
(
$path
)
;
- }
- }
- rmdir
(
$dir
)
;
- }
- ?>
There you have it we successfully created Delete Directory With Files Instantly 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!
Download
You must upgrade your account or reply in the thread to view the hidden content.