note 68074 added to ref.zip

From: Date: Wed, 12 Jul 2006 11:33:44 +0000
Subject: note 68074 added to ref.zip
Groups: php.notes 
Request: Send a blank email to php-notes+get-114691@lists.php.net to get a copy of this message
You can use PHPMyAdmin's zip.lib library. It's available in the package PHPMyAdmin ( http://www.phpmyadmin.net/ ). The zip class is located in /libraries/zip.lib.php Next example generates a file named 'subfolder_in_zip_archive/_settings.php' using information of variable $settings. All files in folder 'folder_holding_files_to_add_to_zip' ($ad_dir) will be added to the archive as well. In this example the raw zip archive data is responded to the browser. Uncomment the lines after 'write the file to disk' if you would like the archive to be stored on disk. The function $zipfile -> addFile requires two parameters. - The first parameter holds raw data and needs to be escaped using php function ‘stripcslashes’ - The second parameter holds the filename in the archive. You can enter complete paths to create complex folder structures A timestamp can be added using the third additional parameter. Regars, Lennart Poot http://www.twing.nl Please visit my Dutch weblog about web development(rss 2.0 supported): http://www.twing.nl/dagtip <?php require_once('zip.lib.php'); $zipfilename = 'zip_archive_to_generate.zip'; $zip_subfolder = 'subfolder_in_zip_archive'; $settings = ' <?php $setting1 = "'.$setting1.'"; $setting2 = "'.$setting2.'"; ?> '; $ad_dir = 'folder_holding_files_to_add_to_zip'; // form is posted, handle it $zipfile = new zipfile(); // generate _settings into zip file $zipfile -> addFile( stripcslashes( $settings ), $zip_subfolder . '/_settings.php' ); if ($handle = opendir($ad_dir)) { while (false !== ($file = readdir($handle))) { if (!is_dir($file) && $file != "." && $file != ".." ) { $f_tmp = @fopen( $ad_dir . '/' . $file, 'r'); if($f_tmp){ $dump_buffer=fread( $f_tmp, filesize($ad_dir . '/' . $file)); $zipfile -> addFile($dump_buffer, $zip_subfolder . '/' . $file); fclose( $f_tmp ); } } } $dump_buffer = $zipfile -> file(); // write the file to disk: /* @file_pointer = fopen('newzip.zip', 'w'); if(@file_pointer){ fwrite( @file_pointer, $zipfile, strlen($zipfile) ); fclose( @file_pointer ); } */ // response zip archive to browser: header('Pragma: public'); header('Content-type: application/zip'); header('Content-length: ' . strlen($dump_buffer)); header('Content-Disposition: attachment; filename="'.$zipfilename.'"'); exit; ?> ---- Server IP: 194.109.193.119 Probable Submitter: 213.93.122.179 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/ref.zip.php Edit -- http://master.php.net/note/edit/68074 Del: integrated -- http://master.php.net/note/delete/68074/integrated Del: useless -- http://master.php.net/note/delete/68074/useless Del: bad code -- http://master.php.net/note/delete/68074/bad+code Del: spam -- http://master.php.net/note/delete/68074/spam Del: non-english -- http://master.php.net/note/delete/68074/non-english Del: in docs -- http://master.php.net/note/delete/68074/in+docs Del: other reasons-- http://master.php.net/note/delete/68074 Reject -- http://master.php.net/note/reject/68074 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#114691) next »