You are here: php zlib « PHP Programming Language « IT news, forums, messages
php zlib

Posted by Rakshasas on 05/24/07 23:10

Hello everyone,

Basically I just found about about zlib and php. For a long while I
have been searching for a provider that allows zip compression through
php scripts and now I have this instead.

I have been playing around with it for a while, but I cannot seem to
gz multiple files at the same time, as in place them in the same
archive.

My goal is to be able to run a php script to compress and backup
folders, and I understand I will need to use recursion to retrieve all
the files but I would like to be able to append files to an archive
before I get into the more advanced part of the script.

Here is some sample code I have modified. I believe I originally found
it on http://php.net/zlib

This script takes a parameter I set to "index.php" and firsts adds
that to the gz file.

Then I hardcoded a second file for testing purposes called
"mainLeft.php". I want to open the index.php.gz and see both index.php
and mainLeft.php, however I only see index.php. However, index.php is
actually contains the contents of mainLeft.php.

Here is the script:

<?php

function compress($srcFileName)
{
$dstFileName = $srcFileName . ".gz";
// getting file content
$fp = fopen( $srcFileName, "r" );
$data = fread ( $fp, filesize( $srcFileName ) );
fclose( $fp );

// writing compressed file
$zp = gzopen( $dstFileName, "w9" );
gzwrite( $zp, $data );


$srcFileName = "mainLeft.php";
// 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 );
}

compress("index.php");
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация