What Will I Learn?
- You will learn how to create a directory from php file
- You will learn how to view the directory
- You will learn how to delete the directory
Requirements
- Basic Knowledges About PHP
- Basic Knowledges About PHP
- WebServer ( In this tutorial I use XAMPP )
Difficulty
- Basic
Tutorial Contents
PHP has provided a function to view, create and change the directory or folder. With open this PHP file you can do all mentioned above without need to do manually. Hacker usually use this PHP function to create a PHP SHELL file for uploading to a victim webserver, and with accessing this file they can monitor all directory or all file in the victim webserver. For more detail lets follow steps bellow:
Reactive your webserver
Create a new folder in xampp/htdocs if you use xampp. While you use Linux create it at var/www.
Open the previous folder from your text editor. and create new php file save as
index.php
Add HTML element as usual
<html>
<head>
<title>Directory</title>
</head>
<body>
</body>
</html>
- Create an input element and a button element
Direktory : <input type="text" name="folder">
<input type="submit" value="Create">
- Open the PHP to write the PHP code
<?php
?>
- To view the all directory we can use opendir() function like this
$path=".";
$dir=opendir($path) or die ("can't open directory");
- Display all directory using While
while($file=readdir($dir)){
echo "<a href='$file'>$file</a> ";
}
- Add delete button and link it to delete.php to delete the directory
while($file=readdir($dir)){
echo "<a href='$file'>$file</a> <a href='delete.php?dir=$file'><button>DELETE</button></a><br>";
}
- To hide the operation file ( the file is use to manipulate the directory) you can use if function, So the code become like this .
while($file=readdir($dir)){
if($file=="."||$file==".."|| $file=="index.php"|| $file=="create.php" || $file=="delete.php")
continue;
echo "<a href='$file'>$file</a> <a href='delete.php?dir=$file'><button>DELETE</button></a><br>";
}
- Close the dir
closedir($dir);
- Open new file and create a PHP file save as
create.php
- Get the name folder that you will create from input element in
index.php
$dir=$_POST['folder'];
- Create the directory using mkdir() function with the permision is 777
mkdir($dir, 777);
- reload to
index.php
header("location: index.php");
- Create new file and save it as
delete.php
- Get the name folder that you will delete from delete button
$folder=$_GET['dir'];
- Delete the directory using rmdir() function
rmdir($folder);
- Reload to
index.php
header("location: index.php")
Save all file and try to run
Create new directory
You can see the directory just created by you under the input element
To Delete the directory click delete button
Full code you can get bellow:
index.php
<html>
<head></head>
<body>
<form action="create.php" method="POST">
Direktory : <input type="text" name="folder">
<input type="submit" value="Create">
</form>
</body>
</html>
<?php
$path=".";
$dir=opendir($path) or die ("can't open directory");
while($file=readdir($dir)){
if($file=="."||$file==".."|| $file=="index.php"|| $file=="create.php" || $file=="delete.php")
continue;
echo "<a href='$file'>$file</a> <a href='delete.php?dir=$file'><button>DELETE</button></a><br>";
}
closedir($dir);
?>
Create.php
<?php
$dir=$_POST['folder'];
mkdir($dir, 777);
header("location: index.php");
?>
delete.php
<?php
$folder=$_GET['dir'];
rmdir($folder);
header("location: index.php")
?>
Curriculum
- PHP Tutorial : Displaying Live STEEM price from bittrex Api on your website using file_get_contents () function
- https://utopian.io/utopian-io/@sogata/how-to-make-steem-calculator-aplication-steem-idr-using-php-and-javascript
Posted on Utopian.io - Rewarding Open Source Contributors
sobat sonan nan droneuh?neu vote long sige
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Ka mulai lake teurimong guenaseh bak si done sang lawetyoo
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
pat si done ??
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Dak meuroeh bahasa aceh sang habeh ta baca..hehe
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
@sogata, Upvote for supporting you.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Mantapp nyan bg berbagi ilmee 👍
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
this is great thanks for the information
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Your contribution cannot be approved because it does not follow the Utopian Rules.
Similar content
You can contact us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank a lot my bro for your suggestion and advice
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hello bro I need a help from you i think you won't support fakes but I found a fake person will you help me @prowhale give him a falg why because my frnd sent a bid amount to vote but they are useing for personal use
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
What can I do??
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Generic comments could be mistaken for spam.
Tips to avoid being flagged
Thank You! ⚜
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit