/ Published in: PHP
Unzip files with PHP.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /************************************** seesaw associates | http://seesaw.net client: file: description: Copyright (C) 2008 Matt Kenefick(.com) **************************************/ class zipArch { /** * Unzip the source_file in the destination dir * * @param string The path to the ZIP-file. * @param string The path where the zipfile should be unpacked, if false the directory of the zip-file is used * @param boolean Indicates if the files will be unpacked in a directory with the name of the zip-file (true) or not (false) (only if the destination directory is set to false!) * @param boolean Overwrite existing files (true) or not (false) * * @return boolean Succesful or not */ function unzip($src_file, $dest_dir=false, $create_zip_name_dir=true, $overwrite=true) { { { } { $splitter = ($create_zip_name_dir === true) ? "." : "/"; // Create the directories to the destination dir if they don't already exist $this->create_dirs($dest_dir); // For every file in the zip-packet { // Now we're going to create the directories in the destination directories // If the file is not in the root dir if ($pos_last_slash !== false) { // Create the directory where the zip-entry should be saved (with a "/" at the end) } // Open the entry { // The name of the file to save on the disk // Check if the files should be overwritten or not { // Get the content of the zip entry // Set the rights { echo "<span style=\"color:#1da319;\">file saved: </span>".$file_name."<br />"; } else { echo "<span style=\"color:red;\">file not found: </span>".$file_name."<br />"; } } // Close the entry } } // Close the zip-file } else { echo "No Zip Archive Found."; return false; } return true; } else { $infoVersion="(use PHP 5.2.0 or later)"; echo "You need to install/enable the php_zip.dll extension $infoVersion"; } } function create_dirs($path) { { $directory_path = ""; foreach($directories as $directory) { $directory_path .= $directory."/"; { } } } } } ?>