Simple Online File Archiver with Comment

Language
In this tutorial, we will create a Simple Online File Archiver with Comment using PHP. This code can compressed multiple files at the same time and write comments on the archive to mark who is the owner of those files.

First thing to do

You have to download and install XAMPP or any local server that run PHP scripts. In my case I used XAMPP as my local server, here's the download link for XAMPP server https://www.apachefriends.org/download.html . If you already installed a local server (XAMPP, WAMP, etc.), just ignore this step.

The Snippet Function

This code will try to compress all the files that you upload then create a zip file. Once the zip file is created, the script downloads the archive then the uploaded file(s) and the generated archive is deleted from the server to save space. If you don't get the logic, take a look at the bunch of code below and the comments on it. 0){ echo "No Selected File"; }else{ // generate filename based on archive generation DateTime $zipname = "FILE-".date('njyHis').".zip"; $archive = new ZipArchive(); $archive->open($zipname, ZipArchive::CREATE); $files = $_FILES['upload']; //Add all uploaded files into the archive 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"); } // write comment to archive before closing $archive->setArchiveComment(file_get_contents("comment.txt")); //closes the archive. This means you cannot edit the archive. $archive->close(); //code to download the generated archive header('Content-type: application/zip'); header('Content-Disposition: attachment; filename="'.$zipname.'"'); readfile($zipname); //deletes all uploaded files foreach($files['name'] as $filedel){ unlink($filedel); } //deletes the generated archive unlink($zipname); //show success message echo "Successfully compressed the file"; } } ?> Tutorial done. I hope that this simple tutorial help you. Enjoy Coding!!

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment