Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

ZipArchive::addFile

(no version information, might be only in CVS)

ZipArchive::addFile -- Adds a file to a ZIP archive from the given path

Описание

bool ZipArchive::addFile ( string filename [, string localname] )

Adds a file to a ZIP archive from a given path

Список параметров

filename

The path to the file to add.

localname

local name inside ZIP archive.

Возвращаемые значения

Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.

Примеры

This example opens a ZIP file archive test.zip and add the file /path/to/index.txt. as newname.txt.

Пример 1. Open and extract

<?php
$zip
= new ZipArchive;
if (
$zip->open('test.zip') === TRUE) {
   
$zip->addFile('/path/to/index.txt', 'newname.txt');
   
$zip->close();
    echo
'ok';
} else {
    echo
'failed';
}
?>


add a note add a note User Contributed Notes
ZipArchive::addFile
Andreas R. newsgroups2005 at geekmail de
03-Apr-2007 06:29
Currently the number of files that can be added using addFile to the ZIP archive (until it is closed) is limited by file descriptors limit. This is an easy workaround (on the bug links below you can find another workarounds):
<?php
   
/** work around file descriptor number limitation (to avoid failure
     * upon adding more than typically 253 or 1024 files to ZIP) */
   
function addFileToZip( $zip, $path, $zipEntryName ) {
       
// this would fail with status ZIPARCHIVE::ER_OPEN
        // after certain number of files is added since
        // ZipArchive internally stores the file descriptors of all the
        // added files and only on close writes the contents to the ZIP file
        // see: http://bugs.php.net/bug.php?id=40494
        // and: http://pecl.php.net/bugs/bug.php?id=9443
        // return $zip->addFile( $path, $zipEntryName );

       
$contents = file_get_contents( $path );
        if (
$contents === false ) {
            return
false;
        }
        return
$zip->addFromString( $zipEntryName, $contents );
    }
?>

ZipArchive::addFromString> <zip_read
Last updated: Sat, 27 Jan 2007
 
 
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330
Z058440144362 Z348613067571