note 89911 added to class.com

From: Date: Sat, 28 Mar 2009 05:35:45 +0000
Subject: note 89911 added to class.com
Groups: php.notes 
Request: Send a blank email to php-notes+get-152549@lists.php.net to get a copy of this message
Here's a way to create an AES-Encrypted ZIP file in PHP, using DotNetZip via the COM class. <?php try { $fname = "zip-generated-from-php-" . date('Y-m-d-His') . ".zip"; $zipOutput = "c:\\temp\\" . $fname; $zip = new COM("Ionic.Zip.ZipFile"); $zip->Name = $zipOutput; $dirToZip= "c:\\temp\\psh"; #$dirToZip= "c:\\dinoch\\webs\\php"; $zip->Encryption = 3; $zip->Password = "AES-Encryption-Is-Secure"; $zip->AddDirectory($dirToZip); $zip->Save(); $zip->Dispose(); if (file_exists($zipOutput)) { header('Cache-Control: no-cache, must-revalidate'); header('Content-Type: application/x-zip'); header('Content-Disposition: attachment; filename=' . $fname); header('Content-Length: ' . filesize($zipOutput)); readfile($zipOutput); unlink($zipOutput); } else { echo '<html>'; echo ' <head>'; echo ' <title>Calling DotNetZip from PHP through COM</title>'; echo ' <link rel="stylesheet" href="basic.css"/>'; echo ' </head>'; echo '<body>'; echo '<h2>Whoops!</h2>' . "<br/>\n"; echo '<p>The file was not successfully generated.</p>'; echo '</body>'; echo '</html>'; } } catch (Exception $e) { echo '<html>'; echo ' <head>'; echo ' <title>Calling DotNetZip from PHP through COM</title>'; echo ' <link rel="stylesheet" href="basic.css"/>'; echo ' </head>'; echo '<body>'; echo '<h2>Whoops!</h2>' . "<br/>\n"; echo '<p>The file was not successfully generated.</p>'; echo '<p>Caught exception: ', $e->getMessage(), '</p>', "\n"; echo '<pre>'; echo $e->getTraceAsString(), "\n"; echo '</pre>'; echo '</body>'; echo '</html>'; } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 24.16.15.71 ---- Manual Page -- http://www.php.net/manual/en/class.com.php Edit -- https://master.php.net/note/edit/89911 Del: integrated -- https://master.php.net/note/delete/89911/integrated Del: useless -- https://master.php.net/note/delete/89911/useless Del: bad code -- https://master.php.net/note/delete/89911/bad+code Del: spam -- https://master.php.net/note/delete/89911/spam Del: non-english -- https://master.php.net/note/delete/89911/non-english Del: in docs -- https://master.php.net/note/delete/89911/in+docs Del: other reasons-- https://master.php.net/note/delete/89911 Reject -- https://master.php.net/note/reject/89911 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#152549) next »