xexseller
Exploit Chainer
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
In this tutorial we will create a How To Get File Extension 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.
And this is the link for the jquery that i used in this tutorial https://jquery.com/.
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 PHP Query
This is the function for the query of the application. This code will store all the data file inputs when clicked. To do that copy and write these inside the text editor, then save it as save_file.php.
Creating the Main Function
This code contains the main function of the application. This code will display all the listed files, and then separate the extension from the original final. To do these just kindly copy and write these block of codes inside the text editor, then save it as get_extension.php
There you have it we successfully created a How To Get File Extension using PHP. I hope that these simple tutorial help you to your projects. 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.
And this is the link for the jquery that i used in this tutorial https://jquery.com/.
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 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 - How To Get File Extension</h3>
- <hr style="border-top:1px dotted;"/>
- <button type="button" class="btn btn-success" data-toggle="modal" data-target="#form_modal"><span class="glyphicon glyphicon-plus"></span> Add File</button>
- <form method="POST" action="" class="pull-right">
- <button name="get" class="btn btn-primary"><span class="glyphicon glyphicon-arrow-down"></span> Get Extension</button>
- </form>
- <br /><br />
- <table class="table table-bordered">
- <thead class="alert-info">
- <tr>
- <td>Filename</td>
- <td>File Extension</td>
- </tr>
- </thead>
- <tbody style="background-color:#fff;">
- <?php
include
'get_extension.php'
?>
- </tbody>
- </table>
- </div>
- <div class="modal fade" id="form_modal" tabindex="-1" role="dialog" aria-hidden="true">
- <div class="modal-dialog" role="document">
- <form action="save_file.php" method="POST" enctype="multipart/form-data">
- <div class="modal-content">
- <div class="modal-body">
- <div class="col-md-3"></div>
- <div class="col-md-6">
- <div class="form-group">
- <label>Filename</label>
- <input type="file" name="file" class="form-control" required="required"/>
- </div>
- </div>
- </div>
- <div style="clear:both;"></div>
- <div class="modal-footer">
- <button type="button" class="btn btn-danger" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Close</button>
- <button name="save" class="btn btn-primary"><span class="glyphicon glyphicon-save"></span> Save</button>
- </div>
- </div>
- </form>
- </div>
- </div>
- </body>
- <script src="js/jquery-3.2.1.min.js"></script>
- <script src="js/bootstrap.js"></script>
- </html>
Creating PHP Query
This is the function for the query of the application. This code will store all the data file inputs when clicked. To do that copy and write these inside the text editor, then save it as save_file.php.
- <?php
- if
(
ISSET
(
$_POST
[
'save'
]
)
)
{
- print_r
(
$_FILES
[
'file'
]
)
;
- $filename
=
$_FILES
[
'file'
]
[
'name'
]
;
- $filetype
=
$_FILES
[
'file'
]
[
'type'
]
;
- $filetemp
=
$_FILES
[
'file'
]
[
'tmp_name'
]
;
- $filesize
=
$_FILES
[
'file'
]
[
'size'
]
;
- if
(
$filesize
>
500000
)
{
- echo
"<script>alert('File too large to upload')</script>"
;
- echo
"<script>window.location = 'index.php'</script>"
;
- }
else
{
- $location
=
"file/"
.
$filename
;
- if
(
move_uploaded_file
(
$filetemp
,
$location
)
)
{
- echo
"<script>alert('File uploaded')</script>"
;
- echo
"<script>window.location = 'index.php'</script>"
;
- }
- }
- }
- ?>
Creating the Main Function
This code contains the main function of the application. This code will display all the listed files, and then separate the extension from the original final. To do these just kindly copy and write these block of codes inside the text editor, then save it as get_extension.php
- <?php
- if
(
!
ISSET
(
$_POST
[
'get'
]
)
)
{
- $files
=
scandir
(
'file/'
)
;
- foreach
(
$files
as
$value
)
{
- if
(
$value
!=
'.'
&&
$value
!=
'..'
)
{
- ?>
- <tr>
- <td><?php
echo
$value
?>
</td>
- <td></td>
- </tr>
- <?php
- }
- }
- }
else
{
- $files
=
scandir
(
'file/'
)
;
- foreach
(
$files
as
$value
)
{
- if
(
$value
!=
'.'
&&
$value
!=
'..'
)
{
- $file
=
explode
(
'.'
,
$value
)
;
- $end
=
end
(
$file
)
;
- ?>
- <tr>
- <td><?php
echo
$file
[
0
]
?>
</td>
- <td><?php
echo
$end
?>
</td>
- </tr>
- <?php
- }
- }
- }
- ?>
There you have it we successfully created a How To Get File Extension using PHP. I hope that these simple tutorial help you to your projects. 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 hidden text.