Creating a zip file using php

Creating a zip file in php is as easy as creating them on your desktop using some zipping software. Php comes with inbuilt class that helps in making a zip file and provides all the functionality that you would ever need. Here is a simple function that I coded for my project. Hope it helps some peoples out there as well.

Php code:

// creates a compressed zip file
function create_zip($files = array(), $filename=array(), $destination = '',$overwrite = false) {
	//if the zip file already exists and overwrite is false, return false
	if(file_exists($destination) && !$overwrite) { return false; }

	$valid_files = array();
	$valid_names = array();

	//if files were passed in...
	if(is_array($files)) {
		//cycle through each file
		foreach($files as $file) {
			//make sure the file exists
			if(is_file($file)) {
				$valid_files[] = $file;
				if(isset($filename[$i]) && $filename[$i]!='') {
				} else {

	//if we have good files...
	if(count($valid_files)) {
		//create the archive
		$zip = new ZipArchive();
		if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
			return false;

		//add the files
		foreach($valid_files as $file) {

		//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;

		//close the zip -- done!

		//check to make sure the file exists
		return file_exists($destination);
	} else {
		return false;

Continue reading “Creating a zip file using php”

Basic 2: Common sense

Trying to figure out the password in this level is a little tricky if compared to level 1, if you had a problem doing that. Well, this level requires a little more than just common sense, and that is some programming knowledge (any language would do it).

Tip: Read the description back again, slowly, and try and understand every single word and line. Or else press continue reading… Continue reading “Basic 2: Common sense”