Backup a Folder To a Zip File With PHP

Many times we need to create a backup utility in our web application. Creating a zip of folder before taking backup is nice idea to reduce size of backup file. You may have seen so many hosting websites and file hosting websites which allow users to compress files as zip file and then download. For making this kind of features, you must add a function of selecting files and then adding it to a zip file.
With the PHP its easy to create a zip of a folder. For this, we can simply use “pclzip.lib.php“. This is a php class library. PclZip gives you the ability to manipulate zip formatted archives. You can create an archive, list the content and extract all its content in the file system.
Download this library from the website and include in your code. See the code snippet below
<?php include('pclzip.lib.php'); $newzip= new PclZip('backup.zip'); $file_list = $newzip->create('images/'); if ($file_list == 0) { die("Error : ".$newzip->errorInfo(true)); } echo "Successfully created zip file for backup"; ?>
I am sure this will solve your problem. If you have any problem in implementing this code you can ask your problems via comment. If you like this post, share it with your friends and subscribe Webtips for daily email updates.
Similar Articles
1 Comments
Leave a comment
Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted.
Thanks for ones marvelous posting! I seriously enjoyed reading it,
you can be a great author. I will make sure to bookmark your blog and will often come back
later on. I want to encourage you to continue your great writing,
have a nice holiday weekend!