eminem6298
Reverse Harem Analyst
LEVEL 1
100 XP
In this tutorial we will create a Simple File Archiver using PHP. This code can compressed multiple files at the same time. 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. In my case I used XAMPP as my local server, here's the link for XAMPP server https://www.apachefriends.org/index.html.
The Main Function
This code contains the main function of the application. This code will try to compress all the files that have upload then create a zip file .To create this just write these block of code inside the text editor.
The Main Interface
This is the interface that display the output of the application,to make this just write these codes inside your text editor, Then save it as index.php,
There you have it we successfully created a Simple File Archiver 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. In my case I used XAMPP as my local server, here's the link for XAMPP server https://www.apachefriends.org/index.html.
The Main Function
This code contains the main function of the application. This code will try to compress all the files that have upload then create a zip file .To create this just write these block of code inside the text editor.
- <?php
- if
(
ISSET
(
$_POST
[
'submit'
]
)
)
{
- if
(
array_sum
(
$_FILES
[
'upload'
]
[
'error'
]
)
>
0
)
{
- echo
"No Selected File"
;
- }
else
{
- $archive
=
new
ZipArchive(
)
;
- $archive
->
open
(
"File.zip"
,
ZipArchive::
CREATE
)
;
- $files
=
$_FILES
[
'upload'
]
;
- for
(
$i
=
0
;
$i
<
count
(
$files
[
'name'
]
)
;
$i
++
)
{
- $tmp_name
=
$files
[
'tmp_name'
]
[
$i
]
;
- $filename
=
$files
[
'name'
]
[
$i
]
;
- move_uploaded_file
(
$tmp_name
,
$filename
)
;
- $archive
->
addFile
(
"$filename
"
)
;
- }
- $archive
->
close
(
)
;
- echo
"Successfully compressed the file"
;
- }
- }
- ?>
The Main Interface
This is the interface that display the output of the application,to make this just write these codes inside your text editor, Then save it as index.php,
- <!
DOCTYPE html>
- <
html lang=
"en"
>
- <
head>
- <
link
rel=
"stylesheet"
type=
"text/css"
href=
"css/bootstrap.css"
/>
- <
meta charset=
"UTF-8"
name=
"viewport"
content=
"width=device-width, initial-scale=1"
/>
- </
head>
- <
body>
- <
nav class
=
"navbar navbar-default"
>
- <
div class
=
"container-fluid"
>
- <
a class
=
"navbar-brand"
href=
"https://sourcecodester.com"
>
Sourcecodster</
a>
- </
div>
- </
nav>
- <
div class
=
"col-md-3"
></
div>
- <
div class
=
"col-md-6 well"
>
- <
h3 class
=
"text-primary"
>
PHP -
Simple File
Archiver</
h3>
- <
hr style=
"border-top:1px dotted #ccc;"
/>
- <
div class
=
"col-md-2"
></
div>
- <
div class
=
"col-md-8"
>
- <
form method=
"POST"
enctype=
"multipart/form-data"
>
- <
div class
=
"form-inline"
>
- <
input class
=
"form-control"
type=
"file"
name=
"upload[]"
multiple/>
- <
button type=
"submit"
class
=
"btn btn-primary form-control"
name=
"submit"
>
Archive</
button
- </
div>
- </
form>
- </
div>
- <
br />
- </
div>
- </
body>
- </
html>
There you have it we successfully created a Simple File Archiver 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.