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, 13 Nov 2009

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 
'失敗';
}
?>


add a note add a note User Contributed Notes
ZipArchive::addFromString
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.

ZipArchive::close> <ZipArchive::addFile
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites