PHP Use zLib to Compress Multiple Files -
$files = array("images/1.jpg", "images/2.jpg", "images/3.jpg"); foreach($files $file){ $temp = null; $fp_in = fopen($file,'rb'); while(!feof($fp_in)){ $temp .= fread($fp_in,1024); } $output[$file] = $temp; fclose($fp_in); } $output = implode('"',$output); $zp = gzopen( 'sequences/backup.gz', "w9" ); gzwrite( $zp, $output ); gzclose( $zp );
the code above works 1 file added archive. best way add multiple files archive using zlib?
require 'tar.php'; $tar_object = new archive_tar("tarname.tar"); $tar_object->seterrorhandling(pear_error_print); // optional error handling $v_list = array("images/1.jpg", "images/2.jpg", "images/3.jpg"); $tar_object->createmodify($v_list, "install"); function compress( $srcfilename, $dstfilename ){ // getting file content $fp = fopen( $srcfilename, "r" ); $data = fread ( $fp, filesize( $srcfilename ) ); fclose( $fp ); // writing compressed file $zp = gzopen( $dstfilename, "w9" ); gzwrite( $zp, $data ); gzclose( $zp ); echo 'success'; } compress("tarname.tar","tarname.tar.gz"); unlink('tarname.tar');
here updated code, of tim, thanks!
Comments
Post a Comment