Monday, October 31, 2016

Create zip file using php

Tags



Nowadays people always archive their big files. The reasons are to save spaces perhaps in their portable hard disk or computer storage. If you are a php developer, this is a must function that a customer will always request. But is it difficult to create a zip file in php? It's actually easier than you thought!

To make things simple, this is the function to create zip files.



Note that files are array type, you can insert as many files as you want as long as it within array.
Ex.
1) single file 

$files_to_zip = array('path/to/file');

2) multiple file

$files_to_zip = array('path/to/file', 'path/to/file', 'path/to/file');

Here how to run the function:

create_zip($files_to_zip,'path/for/output');

Overwrite is set to FALSE. If you wish to have the ability to overwrite existing file, set it to TRUE.




EmoticonEmoticon