Archives | Contacts | Privacy Policy
19 March 2010
Nerd 2.0

Unzip with PHP

Who has not, tons of different archive formats zip, gz, bz, lzma, etc. are on the desktop no problem. When you create a Web application is already complicated in PHP, so I solved it exec () and 7-zip.

In the appendix so a packet with PHP - Function to extract and 7zip - Binary's for 32/64 - bit Linux and Windows systems.

Make to use on Linux systems, the 32/7z and 64/7z executable and integrate into the functions.php script. The extractAll function with the archive and possibly 7zip parameters called. rmdirr () recursively deletes a directory (even if there are files in subdirectories), very handy for just unpacked archives.

Download: php-7z

/* Nerd 2.0
 * March 2010
 * www.nerd20.de
 */
function extractAll($file, $cmd = '') {
	// 64 / 32 Bit - Unix, Windows
	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
		$cmd = '32\7z x '.$file.' -y '.$cmd;
	}
	else {
		if(intval(-6981276091) == -6981276091) {
			$cmd = '64/7z x '.$file.' -y '.$cmd;
		}
		else {
			$cmd = '32/7z x '.$file.' -y '.$cmd;
		}
	}
	// Ausführen
	exec($cmd, $output);
	return $output;
}
/**
 * Delete a file, or a folder and its contents (recursive algorithm)
 *
 * @author      Aidan Lister <aidan@php.net>
 * @version     1.0.3
 * @link        http://aidanlister.com/repos/v/function.rmdirr.php
 * @param       string   $dirname    Directory to delete
 * @return      bool     Returns TRUE on success, FALSE on failure
 */
function rmdirr($dirname)
{
    // Sanity check
    if (!file_exists($dirname)) {
        return false;
    }
    // Simple delete for a file
    if (is_file($dirname) || is_link($dirname)) {
        return unlink($dirname);
    }
    // Loop through the folder
    $dir = dir($dirname);
    while (false !== $entry = $dir->read()) {
        // Skip pointers
        if ($entry == '.' || $entry == '..') {
            continue;
        }
        // Recurse
        rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
    }
    // Clean up
    $dir->close();
    return rmdir($dirname);
}

Vielen Dank an aidanlister.com für das Löschen von Verzeichnissen und dem smarty Blog für 32- / 64-Bit Abfrage.

Ähnliche Beiträge:
Lesezeichensidebar mit Icons
Text gekürzt, aber HTML offen?
Archiv für WordPress! Ohne Links?
Vista – Bugs per Update!
Festplatte Partitionieren, Verschlüsseln, Formatieren

Kommentieren


Ähnliche Beiträge:
Lesezeichensidebar mit Icons
Text gekürzt, aber HTML offen?
Archiv für WordPress! Ohne Links?
Vista – Bugs per Update!
Festplatte Partitionieren, Verschlüsseln, Formatieren

Kommentieren