downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ZipArchive::close> <ZipArchive::addFile
Last updated: Fri, 20 May 2011

view this page in

ZipArchive::addFromString

(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)

ZipArchive::addFromStringAñadir un fichero al archivo ZIP usando su contenido

Descripción

bool ZipArchive::addFromString ( string $localname , string $contents )

Añade un fichero al archivo ZIP usando su contenido.

Parámetros

localname

Nombre de la entrada a crear.

contents

El contenido a usar para crear la entrada. Es usado en modo binary safe.

Valores devueltos

Devuelve TRUE en caso de éxito o FALSE en caso de error.

Ejemplos

Example #1 Añade una entrada al nuevo fichero

<?php
$zip 
= new ZipArchive;
$res $zip->open('test.zip'ZipArchive::CREATE);
if (
$res === TRUE) {
    
$zip->addFromString('test.txt''el contenido del fichero va aquí');
    
$zip->close();
    echo 
'ok';
} else {
    echo 
'failed';
}
?>

Example #2 Añade un fichero en un directorio dentro de un archivo

<?php
$zip 
= new ZipArchive;
if (
$zip->open('test.zip') === TRUE) {
    
$zip->addFromString('dir/test.txt''el contenido del fichero va aquí');
    
$zip->close();
    echo 
'ok';
} else {
    echo 
'falló';
}
?>


ZipArchive::close> <ZipArchive::addFile
Last updated: Fri, 20 May 2011
 
add a note add a note User Contributed Notes ZipArchive::addFromString
calebcjh 19-May-2010 07:54
Although this function displaces files of the same name, in actual fact, the original file is blanked and a new entry is added. The numFiles property is incremented.

Example:

File 1: foo
File 2: bar

$zip->addFromString('foo', 'new foo');

File 1:
File 2: bar
File 3: foo
gbti at ukr dot net 16-Nov-2008 06:01
if you try:

<?php
$zip
->open("file", ZipArchive::CREATE);
$zip->addFromString("russian_letters/options.xml");
?>

wrong directory will be created.

if you try:

<?php
$zip
->addEmptyDir("russian_letters");
?>

All be fine.
Jacques Chester 31-Jan-2007 05:10
Note that this function overwrites existing files of the same name.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites