PHP - Simple File Archiver
Submitted by razormist on Saturday, March 10, 2018 - 22:42.
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.
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!!
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
- echo "No Selected File";
- }else{
- $archive = new ZipArchive();
- $archive->open("File.zip", ZipArchive::CREATE);
- $files = $_FILES['upload'];
- $tmp_name = $files['tmp_name'][$i];
- $filename = $files['name'][$i];
- $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>
- <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">
- <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>
Add new comment
- 250 views