• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

PHP - Simple File Archiver

eminem6298

Reverse Harem Analyst
E Rep
0
0
0
Rep
0
E Vouches
0
0
0
Vouches
0
Posts
97
Likes
93
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
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.
  1. <?php
  2. if

    (

    ISSET

    (

    $_POST

    [

    'submit'

    ]

    )

    )

    {
  3. if

    (

    array_sum

    (

    $_FILES

    [

    'upload'

    ]

    [

    'error'

    ]

    )

    >

    0

    )

    {
  4. echo

    "No Selected File"

    ;
  5. }

    else

    {
  6. $archive

    =

    new

    ZipArchive(

    )

    ;
  7. $archive

    ->

    open

    (

    "File.zip"

    ,

    ZipArchive::

    CREATE

    )

    ;
  8. $files

    =

    $_FILES

    [

    'upload'

    ]

    ;

  9. for

    (

    $i

    =

    0

    ;

    $i

    <

    count

    (

    $files

    [

    'name'

    ]

    )

    ;

    $i

    ++

    )

    {
  10. $tmp_name

    =

    $files

    [

    'tmp_name'

    ]

    [

    $i

    ]

    ;
  11. $filename

    =

    $files

    [

    'name'

    ]

    [

    $i

    ]

    ;

  12. move_uploaded_file

    (

    $tmp_name

    ,

    $filename

    )

    ;

  13. $archive

    ->

    addFile

    (

    "$filename

    "

    )

    ;
  14. }

  15. $archive

    ->

    close

    (

    )

    ;
  16. echo

    "Successfully compressed the file"

    ;
  17. }
  18. }
  19. ?>

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,
  1. <!

    DOCTYPE html>
  2. <

    html lang=

    "en"

    >
  3. <

    head>
  4. <

    link

    rel=

    "stylesheet"

    type=

    "text/css"

    href=

    "css/bootstrap.css"

    />
  5. <

    meta charset=

    "UTF-8"

    name=

    "viewport"

    content=

    "width=device-width, initial-scale=1"

    />
  6. </

    head>
  7. <

    body>
  8. <

    nav class

    =

    "navbar navbar-default"

    >
  9. <

    div class

    =

    "container-fluid"

    >
  10. <

    a class

    =

    "navbar-brand"

    href=

    "https://sourcecodester.com"

    >

    Sourcecodster</

    a>
  11. </

    div>
  12. </

    nav>
  13. <

    div class

    =

    "col-md-3"

    ></

    div>
  14. <

    div class

    =

    "col-md-6 well"

    >
  15. <

    h3 class

    =

    "text-primary"

    >

    PHP -

    Simple File

    Archiver</

    h3>
  16. <

    hr style=

    "border-top:1px dotted #ccc;"

    />
  17. <

    div class

    =

    "col-md-2"

    ></

    div>
  18. <

    div class

    =

    "col-md-8"

    >
  19. <

    form method=

    "POST"

    enctype=

    "multipart/form-data"

    >
  20. <

    div class

    =

    "form-inline"

    >
  21. <

    input class

    =

    "form-control"

    type=

    "file"

    name=

    "upload[]"

    multiple/>
  22. <

    button type=

    "submit"

    class

    =

    "btn btn-primary form-control"

    name=

    "submit"

    >

    Archive</

    button
  23. </

    div>
  24. </

    form>
  25. </

    div>
  26. <

    br />
  27. </

    div>
  28. </

    body>
  29. </

    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.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,512

356,407

356,427

Top
Raidforums