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
[edit] Last updated: Fri, 25 May 2012

view this page in

ZipArchive::addFromString

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

ZipArchive::addFromString内容を指定して、ファイルを ZIP アーカイブに追加する

説明

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

内容を指定して、ファイルを ZIP アーカイブに追加します。

パラメータ

localname

作成するエントリの名前。

contents

エントリを作成するために使用するデータの内容。 バイナリセーフな形式で使用します。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

例1 新しいアーカイブへのエントリの追加

<?php
$zip 
= new ZipArchive;
$res $zip->open('test.zip'ZipArchive::CREATE);
if (
$res === TRUE) {
    
$zip->addFromString('test.txt''ここにファイルの内容を書きます');
    
$zip->close();
    echo 
'成功';
} else {
    echo 
'失敗';
}
?>

例2 アーカイブ内のディレクトリへのファイルの追加

<?php
$zip 
= new ZipArchive;
if (
$zip->open('test.zip') === TRUE) {
    
$zip->addFromString('dir/test.txt''ここにファイルの内容を書きます');
    
$zip->close();
    echo 
'成功';
} else {
    echo 
'失敗';
}
?>


ZipArchive::close> <ZipArchive::addFile
[edit] Last updated: Fri, 25 May 2012
 
add a note add a note User Contributed Notes ZipArchive::addFromString
calebcjh 19-May-2010 06: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 03: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 30-Jan-2007 02:10
Note that this function overwrites existing files of the same name.

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