PhpConcept

Developers Tools

  • Increase font size
  • Default font size
  • Decrease font size
Home PclZip News
PclZip News

PclZip 2.5 : New Features

Print PDF

PclZip 2.5 introduce a security feature and the ability to modify the name of the file archived. To achieve this a large part of the code was modified in order to manage attributes associated to files (or folder) and not only global options. In this release only the name of the file can be modified, but the code was restructured in order to be able to add new features on a per file basis (like add a string as a file, change the file dates, ...). However the code was not modified yet to offer the same feature while extracting files.

The user manual is not yet updated, so you can find below a quick start on this new feature :

$archive = new PclZip("archive.zip");
$list $archive->create(array(
                    array( 
PCLZIP_ATT_FILE_NAME => 'data/file1.txt',
                           
PCLZIP_ATT_FILE_NEW_FULL_NAME => 'newdir/newname.txt'
                         
),
                    array( 
PCLZIP_ATT_FILE_NAME => 'data/file2.txt',
                           
PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'newfilename.txt'
                         
),
                    array( 
PCLZIP_ATT_FILE_NAME => 'data/file3.txt')
                  ),
                  
PCLZIP_OPT_ADD_PATH'newpath',
                  
PCLZIP_OPT_REMOVE_PATH'data');
if (
$list == 0) {
  die(
"ERROR : '".$archive->errorInfo(true)."'");
}
 
  • With PCLZIP_ATT_FILE_NEW_FULL_NAME, 'data/file1.txt' will be completed replaced by 'newdir/newname.txt'. The global options PCLZIP_OPT_ADD_PATH and PCLZIP_OPT_REMOVE_PATH are ignored in this case.
  • With PCLZIP_ATT_FILE_SHORT_NAME, 'file2.txt', will be first replaced by 'newfilename.txt', then the global options will be applied to modify the path on the resulting name.

A security alert was raised by GulfTech explaining that PclZip can be badly used during the file extraction. In fact a script using PclZip to extract a zip file uploaded by a user of a web service, can have the effect of extracting a file and modifying a système file. PclZip support the extraction of files in different folders. Release 2.5 add an option to control that the extracted file is not outside a specific basedir. The idea is similar to the open_basedir restriction of PHP.

 

$archive = new PclZip("archive.zip");
$list $archive->extract(PCLZIP_OPT_EXTRACT_DIR_RESTRICTION'./base_dir');
if (
$list == 0) {
  die(
"ERROR : '".$archive->errorInfo(true)."'");
}
 

In this example archive.zip will be extracted in the current folder. If any file is not with a path inside 'base_dir' PclZip will stop and send an error. Notice that the associated value of PCLZIP_OPT_EXTRACT_DIR_RESTRICTION must be a full path from the root filesystem (and not relative). However the use of './' will indicate that the path is relative to the current path.

 

Last Updated on Sunday, 07 February 2010 15:19
 

PclZip 2.6 : New features on individual files

Print PDF

PclZip 2.6 introduce new granular functions at the file level. You can now add a string as a file in an archive, without the need to create temporary files when a string need to be put in a zip archive.

PclZip 2.6 also correct some bugs.

User manual is not yet updated so you can find some informations bellow :

$archive = new PclZip("archive.zip");
$v_filename = "new_file.txt";
$v_content = "This is the content of file one\nHello second line";
$list = $archive->create(array(
array(
PCLZIP_ATT_FILE_NAME => $v_filename,
PCLZIP_ATT_FILE_CONTENT => $v_content
)
)
);
if (
$list == 0) {
die(
"ERROR : '".$archive->errorInfo(true)."'");
}

The content of string "$v_contenu" will be added in the archive as a file with name 'new_file.txt'.

Last Updated on Sunday, 07 February 2010 15:24